mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
Stop saving JSON files with indents (#2921)
Stop saving json files with 4 indents, this will significantly reduce file size and improve `.set()` performance for config saves when using the JSON driver. Signed-off-by: Draper <guyreis96@gmail.com>
This commit is contained in:
parent
ef8b9b81c3
commit
556af32bb5
1
changelog.d/2921.enhance.rst
Normal file
1
changelog.d/2921.enhance.rst
Normal file
@ -0,0 +1 @@
|
|||||||
|
JSON config files are now stored without indentation, this is to reduce file size and increase performance of write operations.
|
||||||
@ -95,7 +95,7 @@ class JSON(BaseDriver):
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
self.data = {}
|
self.data = {}
|
||||||
with self.data_path.open("w", encoding="utf-8") as fs:
|
with self.data_path.open("w", encoding="utf-8") as fs:
|
||||||
json.dump(self.data, fs, indent=4)
|
json.dump(self.data, fs)
|
||||||
|
|
||||||
def migrate_identifier(self, raw_identifier: int):
|
def migrate_identifier(self, raw_identifier: int):
|
||||||
if self.unique_cog_identifier in self.data:
|
if self.unique_cog_identifier in self.data:
|
||||||
@ -206,7 +206,7 @@ def _save_json(path: Path, data: Dict[str, Any]) -> None:
|
|||||||
tmp_file = "{}-{}.tmp".format(filename, uuid4().fields[0])
|
tmp_file = "{}-{}.tmp".format(filename, uuid4().fields[0])
|
||||||
tmp_path = path.parent / tmp_file
|
tmp_path = path.parent / tmp_file
|
||||||
with tmp_path.open(encoding="utf-8", mode="w") as fs:
|
with tmp_path.open(encoding="utf-8", mode="w") as fs:
|
||||||
json.dump(data, fs, indent=4)
|
json.dump(data, fs)
|
||||||
fs.flush() # This does get closed on context exit, ...
|
fs.flush() # This does get closed on context exit, ...
|
||||||
os.fsync(fs.fileno()) # but that needs to happen prior to this line
|
os.fsync(fs.fileno()) # but that needs to happen prior to this line
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user