@@ -55,8 +55,8 @@ function getConsoleDB(): Database
5555 {
5656 $ ctx = Coroutine::getContext ();
5757
58- if (isset ($ ctx ['consoleDB ' ])) {
59- return $ ctx ['consoleDB ' ];
58+ if (isset ($ ctx ['dbForPlatform ' ])) {
59+ return $ ctx ['dbForPlatform ' ];
6060 }
6161
6262 global $ register ;
@@ -71,7 +71,7 @@ function getConsoleDB(): Database
7171 ->setMetadata ('host ' , \gethostname ())
7272 ->setMetadata ('project ' , '_console ' );
7373 $ database ->setDocumentType ('users ' , User::class);
74- return $ ctx ['consoleDB ' ] = $ database ;
74+ return $ ctx ['dbForPlatform ' ] = $ database ;
7575 }
7676}
7777
@@ -81,12 +81,12 @@ function getProjectDB(Document $project): Database
8181 {
8282 $ ctx = Coroutine::getContext ();
8383
84- if (!isset ($ ctx ['getProjectDB ' ])) {
85- $ ctx ['getProjectDB ' ] = [];
84+ if (!isset ($ ctx ['dbForProject ' ])) {
85+ $ ctx ['dbForProject ' ] = [];
8686 }
8787
88- if (isset ($ ctx ['getProjectDB ' ][$ project ->getSequence ()])) {
89- return $ ctx ['getProjectDB ' ][$ project ->getSequence ()];
88+ if (isset ($ ctx ['dbForProject ' ][$ project ->getSequence ()])) {
89+ return $ ctx ['dbForProject ' ][$ project ->getSequence ()];
9090 }
9191
9292 global $ register ;
@@ -128,7 +128,7 @@ function getProjectDB(Document $project): Database
128128
129129 $ database ->setDocumentType ('users ' , User::class);
130130
131- return $ ctx ['getProjectDB ' ][$ project ->getSequence ()] = $ database ;
131+ return $ ctx ['dbForProject ' ][$ project ->getSequence ()] = $ database ;
132132 }
133133}
134134
@@ -138,8 +138,8 @@ function getCache(): Cache
138138 {
139139 $ ctx = Coroutine::getContext ();
140140
141- if (isset ($ ctx ['getCache ' ])) {
142- return $ ctx ['getCache ' ];
141+ if (isset ($ ctx ['cache ' ])) {
142+ return $ ctx ['cache ' ];
143143 }
144144
145145 global $ register ;
@@ -153,7 +153,7 @@ function getCache(): Cache
153153 $ adapters [] = new CachePool ($ pools ->get ($ value ));
154154 }
155155
156- return $ ctx ['getCache ' ] = new Cache (new Sharding ($ adapters ));
156+ return $ ctx ['cache ' ] = new Cache (new Sharding ($ adapters ));
157157 }
158158}
159159
@@ -163,8 +163,8 @@ function getRedis(): \Redis
163163 {
164164 $ ctx = Coroutine::getContext ();
165165
166- if (isset ($ ctx ['getRedis ' ])) {
167- return $ ctx ['getRedis ' ];
166+ if (isset ($ ctx ['redis ' ])) {
167+ return $ ctx ['redis ' ];
168168 }
169169
170170 $ host = System::getEnv ('_APP_REDIS_HOST ' , 'localhost ' );
@@ -178,20 +178,20 @@ function getRedis(): \Redis
178178 }
179179 $ redis ->setOption (\Redis::OPT_READ_TIMEOUT , -1 );
180180
181- return $ ctx ['getRedis ' ] = $ redis ;
181+ return $ ctx ['redis ' ] = $ redis ;
182182 }
183183}
184184
185185if (!function_exists ('getTimelimit ' )) {
186- function getTimelimit (): TimeLimitRedis
186+ function getTimelimit (string $ key = "" , int $ limit = 0 , int $ seconds = 1 ): TimeLimitRedis
187187 {
188188 $ ctx = Coroutine::getContext ();
189189
190- if (isset ($ ctx ['getTimelimit ' ])) {
191- return $ ctx ['getTimelimit ' ];
190+ if (isset ($ ctx ['timelimit ' ])) {
191+ return $ ctx ['timelimit ' ];
192192 }
193193
194- return $ ctx ['getTimelimit ' ] = new TimeLimitRedis ("" , 0 , 1 , getRedis ());
194+ return $ ctx ['timelimit ' ] = new TimeLimitRedis ($ key , $ limit , $ seconds , getRedis ());
195195 }
196196}
197197
@@ -200,24 +200,24 @@ function getRealtime(): Realtime
200200 {
201201 $ ctx = Coroutine::getContext ();
202202
203- if (isset ($ ctx ['getRealtime ' ])) {
204- return $ ctx ['getRealtime ' ];
203+ if (isset ($ ctx ['realtime ' ])) {
204+ return $ ctx ['realtime ' ];
205205 }
206206
207- return $ ctx ['getRealtime ' ] = new Realtime ();
207+ return $ ctx ['realtime ' ] = new Realtime ();
208208 }
209209}
210210
211211if (!function_exists ('getTelemetry ' )) {
212212 function getTelemetry (int $ workerId ): Utopia \Telemetry \Adapter
213213 {
214- static $ telemetry = null ;
214+ $ ctx = Coroutine:: getContext () ;
215215
216- if ($ telemetry !== null ) {
217- return $ telemetry ;
216+ if (isset ( $ ctx [ ' telemetry ' ]) ) {
217+ return $ ctx [ ' telemetry ' ] ;
218218 }
219219
220- return $ telemetry = new NoTelemetry ();
220+ return $ ctx [ ' telemetry ' ] = new NoTelemetry ();
221221 }
222222}
223223
0 commit comments