Kaynağa Gözat

use_cache_subfolder_for_item: feature

Peter Bieringer 1 yıl önce
ebeveyn
işleme
0fe53e62db

+ 3 - 0
radicale/storage/multifilesystem/__init__.py

@@ -28,6 +28,7 @@ import time
 from typing import ClassVar, Iterator, Optional, Type
 
 from radicale import config
+from radicale.log import logger
 from radicale.storage.multifilesystem.base import CollectionBase, StorageBase
 from radicale.storage.multifilesystem.cache import CollectionPartCache
 from radicale.storage.multifilesystem.create_collection import \
@@ -89,3 +90,5 @@ class Storage(
     def __init__(self, configuration: config.Configuration) -> None:
         super().__init__(configuration)
         self._makedirs_synced(self._filesystem_folder)
+        logger.info("storage location: %r", self._filesystem_folder);
+        logger.info("storage cache subfolder usage for item: %s", self._use_cache_subfolder_for_item);

+ 8 - 0
radicale/storage/multifilesystem/base.py

@@ -70,6 +70,7 @@ class StorageBase(storage.BaseStorage):
 
     _filesystem_folder: str
     _filesystem_fsync: bool
+    _use_cache_subfolder_for_item: bool
 
     def __init__(self, configuration: config.Configuration) -> None:
         super().__init__(configuration)
@@ -77,10 +78,17 @@ class StorageBase(storage.BaseStorage):
             "storage", "filesystem_folder")
         self._filesystem_fsync = configuration.get(
             "storage", "_filesystem_fsync")
+        self._use_cache_subfolder_for_item = configuration.get(
+            "storage", "use_cache_subfolder_for_item")
 
     def _get_collection_root_folder(self) -> str:
         return os.path.join(self._filesystem_folder, "collection-root")
 
+    def _get_collection_cache_folder(self, path, folder, subfolder) -> str:
+        if self._use_cache_subfolder_for_item == True and subfolder == "item":
+            path = path.replace(os.path.join(self._filesystem_folder, "collection-root"), os.path.join(self._filesystem_folder, "collection-cache"))
+        return os.path.join(path, folder, subfolder)
+
     def _fsync(self, f: IO[AnyStr]) -> None:
         if self._filesystem_fsync:
             try:

+ 3 - 3
radicale/storage/multifilesystem/cache.py

@@ -81,7 +81,7 @@ class CollectionPartCache(CollectionBase):
         if not cache_hash:
             cache_hash = self._item_cache_hash(
                 item.serialize().encode(self._encoding))
-        cache_folder = os.path.join(self._filesystem_path, ".Radicale.cache",
+        cache_folder = self._storage._get_collection_cache_folder(self._filesystem_path, ".Radicale.cache",
                                     "item")
         content = self._item_cache_content(item)
         self._storage._makedirs_synced(cache_folder)
@@ -95,7 +95,7 @@ class CollectionPartCache(CollectionBase):
 
     def _load_item_cache(self, href: str, cache_hash: str
                          ) -> Optional[CacheContent]:
-        cache_folder = os.path.join(self._filesystem_path, ".Radicale.cache",
+        cache_folder = self._storage._get_collection_cache_folder(self._filesystem_path, ".Radicale.cache",
                                     "item")
         try:
             with open(os.path.join(cache_folder, href), "rb") as f:
@@ -110,7 +110,7 @@ class CollectionPartCache(CollectionBase):
         return None
 
     def _clean_item_cache(self) -> None:
-        cache_folder = os.path.join(self._filesystem_path, ".Radicale.cache",
+        cache_folder = self._storage._get_collection_cache_folder(self._filesystem_path, ".Radicale.cache",
                                     "item")
         self._clean_cache(cache_folder, (
             e.name for e in os.scandir(cache_folder) if not

+ 2 - 2
radicale/storage/multifilesystem/move.py

@@ -41,9 +41,9 @@ class StoragePartMove(StorageBase):
         if item.collection._filesystem_path != to_collection._filesystem_path:
             self._sync_directory(item.collection._filesystem_path)
         # Move the item cache entry
-        cache_folder = os.path.join(item.collection._filesystem_path,
+        cache_folder = self._get_collection_cache_folder(item.collection._filesystem_path,
                                     ".Radicale.cache", "item")
-        to_cache_folder = os.path.join(to_collection._filesystem_path,
+        to_cache_folder = self._get_collection_cache_folder(to_collection._filesystem_path,
                                        ".Radicale.cache", "item")
         self._makedirs_synced(to_cache_folder)
         try:

+ 1 - 1
radicale/storage/multifilesystem/upload.py

@@ -75,7 +75,7 @@ class CollectionPartUpload(CollectionPartGet, CollectionPartCache,
             yield radicale_item.find_available_uid(
                 lambda href: not is_safe_free_href(href), suffix)
 
-        cache_folder = os.path.join(self._filesystem_path,
+        cache_folder = self._storage._get_collection_cache_folder(self._filesystem_path,
                                     ".Radicale.cache", "item")
         self._storage._makedirs_synced(cache_folder)
         for item in items: