use_cache_subfolder_for_item: feature

This commit is contained in:
Peter Bieringer 2024-12-03 21:32:57 +01:00
parent f754f28518
commit 0fe53e62db
5 changed files with 17 additions and 6 deletions

View file

@ -28,6 +28,7 @@ import time
from typing import ClassVar, Iterator, Optional, Type from typing import ClassVar, Iterator, Optional, Type
from radicale import config from radicale import config
from radicale.log import logger
from radicale.storage.multifilesystem.base import CollectionBase, StorageBase from radicale.storage.multifilesystem.base import CollectionBase, StorageBase
from radicale.storage.multifilesystem.cache import CollectionPartCache from radicale.storage.multifilesystem.cache import CollectionPartCache
from radicale.storage.multifilesystem.create_collection import \ from radicale.storage.multifilesystem.create_collection import \
@ -89,3 +90,5 @@ class Storage(
def __init__(self, configuration: config.Configuration) -> None: def __init__(self, configuration: config.Configuration) -> None:
super().__init__(configuration) super().__init__(configuration)
self._makedirs_synced(self._filesystem_folder) 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);

View file

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

View file

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

View file

@ -41,9 +41,9 @@ class StoragePartMove(StorageBase):
if item.collection._filesystem_path != to_collection._filesystem_path: if item.collection._filesystem_path != to_collection._filesystem_path:
self._sync_directory(item.collection._filesystem_path) self._sync_directory(item.collection._filesystem_path)
# Move the item cache entry # 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") ".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") ".Radicale.cache", "item")
self._makedirs_synced(to_cache_folder) self._makedirs_synced(to_cache_folder)
try: try:

View file

@ -75,7 +75,7 @@ class CollectionPartUpload(CollectionPartGet, CollectionPartCache,
yield radicale_item.find_available_uid( yield radicale_item.find_available_uid(
lambda href: not is_safe_free_href(href), suffix) 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") ".Radicale.cache", "item")
self._storage._makedirs_synced(cache_folder) self._storage._makedirs_synced(cache_folder)
for item in items: for item in items: