2424from tgdb .application .view_tuples import ViewTuples
2525from tgdb .entities .horizon .horizon import Horizon , horizon
2626from tgdb .entities .horizon .transaction import PreparedCommit
27+ from tgdb .entities .relation .relation import Relation
2728from tgdb .infrastructure .adapters .buffer import (
2829 InMemoryBuffer ,
2930 InTelegramReplicablePreparedCommitBuffer ,
3536from tgdb .infrastructure .adapters .shared_horizon import InMemorySharedHorizon
3637from tgdb .infrastructure .adapters .tuples import InTelegramHeapTuples
3738from tgdb .infrastructure .adapters .uuids import UUIDs4
39+ from tgdb .infrastructure .async_map import AsyncMap
3840from tgdb .infrastructure .async_queque import AsyncQueque
3941from tgdb .infrastructure .pyyaml .conf import Conf , VacuumConf
4042from tgdb .infrastructure .telethon .client_pool import (
5456BotPool = NewType ("BotPool" , TelegramClientPool )
5557UserBotPool = NewType ("UserBotPool" , TelegramClientPool )
5658
59+ RelationCache = NewType ("RelationCache" , InMemoryDb [Relation ])
60+
5761
5862def conf_vacuum (
5963 conf : VacuumConf , bot_pool : BotPool , user_bot_pool : UserBotPool
@@ -73,12 +77,12 @@ class CommonProvider(Provider):
7377 provide_clock = provide (PerfCounterClock , provides = Clock , scope = Scope .APP )
7478 provide_uuids = provide (UUIDs4 , provides = UUIDs , scope = Scope .APP )
7579 provide_queque = provide (
76- lambda : InMemoryQueque (AsyncQueque ()),
80+ staticmethod ( lambda : InMemoryQueque (AsyncQueque () )),
7781 provides = Queque [Sequence [PreparedCommit ]],
7882 scope = Scope .APP
7983 )
8084 provide_channel = provide (
81- AsyncMapChannel ,
85+ staticmethod ( lambda : AsyncMapChannel ( AsyncMap ())) ,
8286 provides = Channel ,
8387 scope = Scope .APP ,
8488 )
@@ -174,20 +178,24 @@ def provide_buffer(
174178
175179 return InTelegramReplicablePreparedCommitBuffer (buffer , in_tg_bytes )
176180
181+ @provide (scope = Scope .APP )
182+ def provide_relation_cache (self ) -> RelationCache :
183+ return RelationCache (InMemoryDb ())
184+
177185 @provide (scope = Scope .APP )
178186 def provide_relations (
179187 self ,
180188 conf : Conf ,
181189 bot_pool : BotPool ,
182190 user_bot_pool : UserBotPool ,
191+ relation_cache : RelationCache ,
183192 ) -> Relations :
184193 autovacuum = conf_vacuum (conf .relations .vacuum , bot_pool , user_bot_pool )
185194 in_tg_bytes = InTelegramBytes (
186195 bot_pool , user_bot_pool , conf .relations .chat , autovacuum
187196 )
188- cached_relations = InMemoryDb ()
189197
190- return InTelegramReplicableRelations (in_tg_bytes , cached_relations )
198+ return InTelegramReplicableRelations (in_tg_bytes , relation_cache )
191199
192200 provide_commit_transaction = provide (CommitTransaction , scope = Scope .APP )
193201 provide_output_commits = provide (OutputCommits , scope = Scope .APP )
0 commit comments