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:
Draper 2019-08-07 01:13:31 +01:00 committed by Toby Harradine
parent ef8b9b81c3
commit 556af32bb5
2 changed files with 3 additions and 2 deletions

View File

@ -0,0 +1 @@
JSON config files are now stored without indentation, this is to reduce file size and increase performance of write operations.

View File

@ -95,7 +95,7 @@ class JSON(BaseDriver):
except FileNotFoundError:
self.data = {}
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):
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_path = path.parent / tmp_file
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, ...
os.fsync(fs.fileno()) # but that needs to happen prior to this line