fix(config): expose system config increment service

This commit is contained in:
jxxghp
2026-08-31 06:47:30 +08:00
parent 61419b65a2
commit b63bcbe94b
2 changed files with 20 additions and 0 deletions

View File

@@ -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:

View File

@@ -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()