mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2025-12-18 05:55:45 +00:00
Compare commits
1 Commits
screenshot
...
orjson
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8100a809ca |
@@ -22,6 +22,13 @@ import uuid as uuid_builder
|
|||||||
from loguru import logger
|
from loguru import logger
|
||||||
from blinker import signal
|
from blinker import signal
|
||||||
|
|
||||||
|
# Try to import orjson for faster JSON serialization
|
||||||
|
try:
|
||||||
|
import orjson
|
||||||
|
HAS_ORJSON = True
|
||||||
|
except ImportError:
|
||||||
|
HAS_ORJSON = False
|
||||||
|
|
||||||
from .processors import get_custom_watch_obj_for_processor
|
from .processors import get_custom_watch_obj_for_processor
|
||||||
from .processors.restock_diff import Restock
|
from .processors.restock_diff import Restock
|
||||||
|
|
||||||
@@ -426,9 +433,14 @@ class ChangeDetectionStore:
|
|||||||
# Re #286 - First write to a temp file, then confirm it looks OK and rename it
|
# Re #286 - First write to a temp file, then confirm it looks OK and rename it
|
||||||
# This is a fairly basic strategy to deal with the case that the file is corrupted,
|
# This is a fairly basic strategy to deal with the case that the file is corrupted,
|
||||||
# system was out of memory, out of RAM etc
|
# system was out of memory, out of RAM etc
|
||||||
with open(self.json_store_path+".tmp", 'w') as json_file:
|
if HAS_ORJSON:
|
||||||
# Use compact JSON in production for better performance
|
# Use orjson for faster serialization
|
||||||
json.dump(data, json_file, indent=2)
|
with open(self.json_store_path+".tmp", 'wb') as json_file:
|
||||||
|
json_file.write(orjson.dumps(data, option=orjson.OPT_INDENT_2))
|
||||||
|
else:
|
||||||
|
# Fallback to standard json module
|
||||||
|
with open(self.json_store_path+".tmp", 'w') as json_file:
|
||||||
|
json.dump(data, json_file, indent=2)
|
||||||
os.replace(self.json_store_path+".tmp", self.json_store_path)
|
os.replace(self.json_store_path+".tmp", self.json_store_path)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error writing JSON!! (Main JSON file save was skipped) : {str(e)}")
|
logger.error(f"Error writing JSON!! (Main JSON file save was skipped) : {str(e)}")
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ chardet>2.3.0
|
|||||||
wtforms~=3.2
|
wtforms~=3.2
|
||||||
jsonpath-ng~=1.7.0
|
jsonpath-ng~=1.7.0
|
||||||
|
|
||||||
|
# Fast JSON serialization for better performance
|
||||||
|
orjson~=3.10
|
||||||
|
|
||||||
# dnspython - Used by paho-mqtt for MQTT broker resolution
|
# dnspython - Used by paho-mqtt for MQTT broker resolution
|
||||||
# Version pin removed since eventlet (which required the specific 2.6.1 pin) has been eliminated
|
# Version pin removed since eventlet (which required the specific 2.6.1 pin) has been eliminated
|
||||||
# paho-mqtt will install compatible dnspython version automatically
|
# paho-mqtt will install compatible dnspython version automatically
|
||||||
|
|||||||
Reference in New Issue
Block a user