@@ -292,7 +292,9 @@ protected function process(iInput $input, iOutput $output): int
292292
293293 unset($ backend );
294294
295- $ this ->logger ->notice ("SYSTEM: Getting users list from '{backends}'. " , [
295+ $ this ->logger ->notice (
296+ "SYSTEM: Getting users list from '{backends}'. " ,
297+ [
296298 'backends ' => join (', ' , array_map (fn ($ backend ) => $ backend ['name ' ], $ backends ))
297299 ]
298300 );
@@ -309,6 +311,7 @@ protected function process(iInput $input, iOutput $output): int
309311
310312 try {
311313 foreach ($ client ->getUsersList (['tokens ' => true ]) as $ user ) {
314+ /** @var array $info */
312315 $ info = $ backend ;
313316 $ info ['token ' ] = ag ($ user , 'token ' , ag ($ backend , 'token ' ));
314317 $ info ['user ' ] = ag ($ user , 'id ' , ag ($ info , 'user ' ));
@@ -370,9 +373,12 @@ protected function process(iInput $input, iOutput $output): int
370373 'memory ' => getMemoryUsage (),
371374 ]);
372375 $ perUserCache = perUserCacheAdapter ($ userName );
373- $ perUserMapper = perUserMapper ( $ this ->mapper , $ userName )
376+ $ perUserMapper = $ this ->mapper -> withDB ( perUserDb ( $ userName) )
374377 ->withCache ($ perUserCache )
375- ->withLogger ($ this ->logger )->loadData ();
378+ ->withLogger ($ this ->logger )
379+ ->withOptions (array_replace_recursive ($ this ->mapper ->getOptions (), [Options::ALT_NAME => $ userName ]))
380+ ->loadData ();
381+
376382 $ this ->logger ->info ("SYSTEM: loading of '{user}' mapper data completed using '{memory}' of memory. " , [
377383 'user ' => $ userName ,
378384 'memory ' => getMemoryUsage (),
@@ -432,21 +438,20 @@ protected function process(iInput $input, iOutput $output): int
432438
433439 foreach ($ changes as $ b => $ changed ) {
434440 $ count = count ($ changed );
435- $ this ->logger ->notice ("SYSTEM: Changes detected for '{name}: {backend}' are '{changes}'. " , [
436- 'name ' => $ displayName ,
437- 'backend ' => $ b ,
438- 'changes ' => $ count ,
439- 'items ' => array_map (
440- fn (iState $ i ) => [
441- 'title ' => $ i ->getName (),
442- 'state ' => $ i ->isWatched () ? 'played ' : 'unplayed ' ,
443- 'meta ' => $ i ->isSynced (array_keys ($ list )),
444- ],
445- $ changed
446- )
447- ]);
448-
449441 if ($ count >= 1 ) {
442+ $ this ->logger ->notice ("SYSTEM: Changes detected for '{name}: {backend}' are '{changes}'. " , [
443+ 'name ' => $ displayName ,
444+ 'backend ' => $ b ,
445+ 'changes ' => $ count ,
446+ 'items ' => array_map (
447+ fn (iState $ i ) => [
448+ 'title ' => $ i ->getName (),
449+ 'state ' => $ i ->isWatched () ? 'played ' : 'unplayed ' ,
450+ 'meta ' => $ i ->isSynced (array_keys ($ list )),
451+ ],
452+ $ changed
453+ )
454+ ]);
450455 /** @var iClient $client */
451456 $ client = $ list [$ b ]['class ' ];
452457 $ client ->updateState ($ changed , $ this ->queue );
@@ -470,13 +475,13 @@ protected function process(iInput $input, iOutput $output): int
470475 ],
471476 ]);
472477
473- // -- commit changes
478+ // -- Release memory.
474479 if (false === $ input ->getOption ('dry-run ' )) {
475480 $ perUserMapper ->commit ();
481+ } else {
482+ $ perUserMapper ->reset ();
476483 }
477484
478- // -- Release memory.
479- $ perUserMapper ->reset ();
480485 $ this ->logger ->info ("SYSTEM: Memory usage after reset '{memory}'. " , [
481486 'memory ' => getMemoryUsage (),
482487 ]);
@@ -791,9 +796,7 @@ private function generate_users_list(array $users, bool $includeMainUser, array
791796 }
792797
793798 // Ensure $matchedUser['client_data']['options'] is an array
794- if (!isset ($ matchedUser ['client_data ' ]['options ' ]) || !is_array (
795- $ matchedUser ['client_data ' ]['options ' ]
796- )) {
799+ if (!isset ($ matchedUser ['client_data ' ]['options ' ]) || !is_array ($ matchedUser ['client_data ' ]['options ' ])) {
797800 $ matchedUser ['client_data ' ]['options ' ] = [];
798801 }
799802
0 commit comments