|
2 | 2 | from collections.abc import AsyncIterator, Sequence |
3 | 3 | from typing import NewType |
4 | 4 |
|
5 | | -from dishka import Provider, Scope, make_container, provide |
| 5 | +from dishka import AnyOf, Provider, Scope, make_container, provide |
6 | 6 | from in_memory_db import InMemoryDb |
7 | 7 |
|
8 | 8 | from tgdb.application.common.ports.buffer import Buffer |
@@ -69,16 +69,17 @@ def provide_conf(self, envs: Envs) -> TgdbConfig: |
69 | 69 | class CommonProvider(Provider): |
70 | 70 | provide_clock = provide(PerfCounterClock, provides=Clock, scope=Scope.APP) |
71 | 71 | provide_uuids = provide(UUIDs4, provides=UUIDs, scope=Scope.APP) |
72 | | - provide_queque = provide( |
| 72 | + provide_commit_queque = provide( |
73 | 73 | staticmethod(lambda: InMemoryQueque(AsyncQueque())), |
74 | 74 | provides=Queque[Sequence[Commit | PreparedCommit]], |
75 | 75 | scope=Scope.APP |
76 | 76 | ) |
77 | | - provide_channel = provide( |
78 | | - staticmethod(lambda: AsyncMapChannel(AsyncMap())), |
79 | | - provides=Channel, |
80 | | - scope=Scope.APP, |
81 | | - ) |
| 77 | + |
| 78 | + @provide(scope=Scope.APP) |
| 79 | + def provide_channel(self, config: TgdbConfig) -> Channel: |
| 80 | + return AsyncMapChannel( |
| 81 | + AsyncMap(), config.horizon.transaction.max_age_seconds |
| 82 | + ) |
82 | 83 |
|
83 | 84 | @provide(scope=Scope.APP) |
84 | 85 | async def provide_bot_pool( |
@@ -178,22 +179,17 @@ async def provide_buffer( |
178 | 179 | async with biffer: |
179 | 180 | yield biffer |
180 | 181 |
|
181 | | - @provide(scope=Scope.APP) |
182 | | - def provide_relation_cache(self) -> RelationCache: |
183 | | - return RelationCache(InMemoryDb()) |
184 | | - |
185 | | - @provide(scope=Scope.APP) |
| 182 | + @provide(scope=Scope.APP, ) |
186 | 183 | async def provide_relations( |
187 | 184 | self, |
188 | 185 | config: TgdbConfig, |
189 | 186 | bot_pool: BotPool, |
190 | 187 | user_bot_pool: UserBotPool, |
191 | | - relation_cache: RelationCache, |
192 | | - ) -> AsyncIterator[Relations]: |
| 188 | + ) -> AsyncIterator[AnyOf[Relations, InTelegramReplicableRelations]]: |
193 | 189 | in_tg_bytes = InTelegramBytes( |
194 | 190 | bot_pool, user_bot_pool, config.relations.chat |
195 | 191 | ) |
196 | | - relations = InTelegramReplicableRelations(in_tg_bytes, relation_cache) |
| 192 | + relations = InTelegramReplicableRelations(in_tg_bytes, InMemoryDb()) |
197 | 193 |
|
198 | 194 | async with relations: |
199 | 195 | yield relations |
|
0 commit comments