mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-10-31 20:34:48 +08:00
fix(config): expose system config increment service
This commit is contained in:
@@ -29,6 +29,9 @@ class SystemConfigWriter(Protocol):
|
||||
def delete(self, key: Any) -> Any:
|
||||
"""删除配置。"""
|
||||
|
||||
def increment(self, key: SystemConfigKey, step: int = 1) -> int:
|
||||
"""原子递增整数配置并返回递增后的值。"""
|
||||
|
||||
|
||||
class ConfigurationRepository(SystemConfigReader, SystemConfigWriter, Protocol):
|
||||
"""兼容同时提供读写能力的旧配置仓储。"""
|
||||
@@ -334,6 +337,10 @@ class SystemConfigService:
|
||||
"""写入配置。"""
|
||||
return self._writer.set(key, value)
|
||||
|
||||
def increment(self, key: SystemConfigKey, step: int = 1) -> int:
|
||||
"""原子递增整数系统配置,保持计数更新由持久化端口负责。"""
|
||||
return self._writer.increment(key, step)
|
||||
|
||||
async def async_set(self, key: Any, value: Any) -> bool | None:
|
||||
"""异步写入配置,并等待数据库提交或回滚完成。"""
|
||||
if self._async_executor is None:
|
||||
|
||||
@@ -20,6 +20,7 @@ from app.application.configuration import (
|
||||
get_transfer_retry_config,
|
||||
)
|
||||
from app.application.security.userconfig import UserConfigurationService
|
||||
from app.schemas.types import SystemConfigKey
|
||||
|
||||
|
||||
class _InlineDatabaseExecutor:
|
||||
@@ -108,6 +109,18 @@ def test_system_config_service_supports_separate_reader_and_writer() -> None:
|
||||
]
|
||||
|
||||
|
||||
def test_system_config_service_forwards_atomic_increment() -> None:
|
||||
"""共享识别命中计数应通过应用服务转发到持久化原子递增端口。"""
|
||||
reader = MagicMock()
|
||||
writer = MagicMock()
|
||||
writer.increment.return_value = 3
|
||||
service = SystemConfigService(reader=reader, writer=writer)
|
||||
|
||||
assert service.increment(SystemConfigKey.MediaRecognizeShareCount) == 3
|
||||
|
||||
writer.increment.assert_called_once_with(SystemConfigKey.MediaRecognizeShareCount, 1)
|
||||
|
||||
|
||||
def test_user_configuration_service_supports_sync_and_async_writes() -> None:
|
||||
"""用户配置服务的同步与异步入口执行同一仓储方法。"""
|
||||
repository = MagicMock()
|
||||
|
||||
Reference in New Issue
Block a user