mirror of
https://github.com/Kozea/Radicale.git
synced 2025-06-26 16:45:52 +00:00
Merge pull request #1660 from pbiering/show-mtime-info-by-default
Show mtime info by default
This commit is contained in:
commit
b784f476b4
1 changed files with 57 additions and 52 deletions
|
@ -92,6 +92,52 @@ class Storage(
|
|||
|
||||
_collection_class: ClassVar[Type[Collection]] = Collection
|
||||
|
||||
def _analyse_mtime(self):
|
||||
# calculate and display mtime resolution
|
||||
path = os.path.join(self._filesystem_folder, ".Radicale.mtime_test")
|
||||
try:
|
||||
with open(path, "w") as f:
|
||||
f.write("mtime_test")
|
||||
f.close
|
||||
except Exception as e:
|
||||
logger.error("Storage item mtime resolution test not possible, cannot write file: %r (%s)", path, e)
|
||||
raise
|
||||
# set mtime_ns for tests
|
||||
os.utime(path, times=None, ns=(MTIME_NS_TEST, MTIME_NS_TEST))
|
||||
logger.debug("Storage item mtime resoultion test set: %d" % MTIME_NS_TEST)
|
||||
mtime_ns = os.stat(path).st_mtime_ns
|
||||
logger.debug("Storage item mtime resoultion test get: %d" % mtime_ns)
|
||||
# start analysis
|
||||
precision = 1
|
||||
mtime_ns_test = MTIME_NS_TEST
|
||||
while mtime_ns > 0:
|
||||
if mtime_ns == mtime_ns_test:
|
||||
break
|
||||
factor = 2
|
||||
if int(mtime_ns / factor) == int(mtime_ns_test / factor):
|
||||
precision = precision * factor
|
||||
break
|
||||
factor = 5
|
||||
if int(mtime_ns / factor) == int(mtime_ns_test / factor):
|
||||
precision = precision * factor
|
||||
break
|
||||
precision = precision * 10
|
||||
mtime_ns = int(mtime_ns / 10)
|
||||
mtime_ns_test = int(mtime_ns_test / 10)
|
||||
unit = "ns"
|
||||
precision_unit = precision
|
||||
if precision >= 1000000000:
|
||||
precision_unit = int(precision / 1000000000)
|
||||
unit = "s"
|
||||
elif precision >= 1000000:
|
||||
precision_unit = int(precision / 1000000)
|
||||
unit = "ms"
|
||||
elif precision >= 1000:
|
||||
precision_unit = int(precision / 1000)
|
||||
unit = "us"
|
||||
os.remove(path)
|
||||
return (precision, precision_unit, unit)
|
||||
|
||||
def __init__(self, configuration: config.Configuration) -> None:
|
||||
super().__init__(configuration)
|
||||
logger.info("Storage location: %r", self._filesystem_folder)
|
||||
|
@ -101,58 +147,17 @@ class Storage(
|
|||
logger.info("Storage cache subfolder usage for 'history': %s", self._use_cache_subfolder_for_history)
|
||||
logger.info("Storage cache subfolder usage for 'sync-token': %s", self._use_cache_subfolder_for_synctoken)
|
||||
logger.info("Storage cache use mtime and size for 'item': %s", self._use_mtime_and_size_for_item_cache)
|
||||
if self._use_mtime_and_size_for_item_cache is True:
|
||||
# calculate and display mtime resolution
|
||||
path = os.path.join(self._filesystem_folder, ".Radicale.mtime_test")
|
||||
try:
|
||||
with open(path, "w") as f:
|
||||
f.write("mtime_test")
|
||||
f.close
|
||||
except Exception as e:
|
||||
logger.error("Storage item mtime resolution test not possible, cannot write file: %r (%s)", path, e)
|
||||
raise
|
||||
# set mtime_ns for tests
|
||||
os.utime(path, times=None, ns=(MTIME_NS_TEST, MTIME_NS_TEST))
|
||||
logger.debug("Storage item mtime resoultion test set: %d" % MTIME_NS_TEST)
|
||||
mtime_ns = os.stat(path).st_mtime_ns
|
||||
logger.debug("Storage item mtime resoultion test get: %d" % mtime_ns)
|
||||
# start analysis
|
||||
precision = 1
|
||||
mtime_ns_test = MTIME_NS_TEST
|
||||
while mtime_ns > 0:
|
||||
if mtime_ns == mtime_ns_test:
|
||||
break
|
||||
factor = 2
|
||||
if int(mtime_ns / factor) == int(mtime_ns_test / factor):
|
||||
precision = precision * factor
|
||||
break
|
||||
factor = 5
|
||||
if int(mtime_ns / factor) == int(mtime_ns_test / factor):
|
||||
precision = precision * factor
|
||||
break
|
||||
precision = precision * 10
|
||||
mtime_ns = int(mtime_ns / 10)
|
||||
mtime_ns_test = int(mtime_ns_test / 10)
|
||||
unit = "ns"
|
||||
precision_log = precision
|
||||
if precision >= 1000000000:
|
||||
precision_log = int(precision / 1000000000)
|
||||
unit = "s"
|
||||
elif precision >= 1000000:
|
||||
precision_log = int(precision / 1000000)
|
||||
unit = "ms"
|
||||
elif precision >= 1000:
|
||||
precision_log = int(precision / 1000)
|
||||
unit = "us"
|
||||
os.remove(path)
|
||||
if precision >= 100000000:
|
||||
# >= 100 ms
|
||||
logger.warning("Storage item mtime resolution test result: %d %s (VERY RISKY ON PRODUCTION SYSTEMS)" % (precision_log, unit))
|
||||
elif precision >= 10000000:
|
||||
# >= 10 ms
|
||||
logger.warning("Storage item mtime resolution test result: %d %s (RISKY ON PRODUCTION SYSTEMS)" % (precision_log, unit))
|
||||
else:
|
||||
logger.info("Storage item mtime resolution test result: %d %s" % (precision_log, unit))
|
||||
(precision, precision_unit, unit) = self._analyse_mtime()
|
||||
if precision >= 100000000:
|
||||
# >= 100 ms
|
||||
logger.warning("Storage item mtime resolution test result: %d %s (VERY RISKY ON PRODUCTION SYSTEMS)" % (precision_unit, unit))
|
||||
elif precision >= 10000000:
|
||||
# >= 10 ms
|
||||
logger.warning("Storage item mtime resolution test result: %d %s (RISKY ON PRODUCTION SYSTEMS)" % (precision_unit, unit))
|
||||
else:
|
||||
logger.info("Storage item mtime resolution test result: %d %s" % (precision_unit, unit))
|
||||
if self._use_mtime_and_size_for_item_cache is False:
|
||||
logger.info("Storage cache using mtime and size for 'item' may be an option in case of performance issues")
|
||||
logger.debug("Storage cache action logging: %s", self._debug_cache_actions)
|
||||
if self._use_cache_subfolder_for_item is True or self._use_cache_subfolder_for_history is True or self._use_cache_subfolder_for_synctoken is True:
|
||||
logger.info("Storage cache subfolder: %r", self._get_collection_cache_folder())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue