4141use libphonenumber \PhoneNumberFormat ;
4242use libphonenumber \PhoneNumberUtil ;
4343use OC \Profile \TProfileHelper ;
44+ use OC \Cache \CappedMemoryCache ;
4445use OCA \Settings \BackgroundJobs \VerifyUserData ;
4546use OCP \Accounts \IAccount ;
4647use OCP \Accounts \IAccountManager ;
@@ -116,6 +117,7 @@ class AccountManager implements IAccountManager {
116117 private $ crypto ;
117118 /** @var IFactory */
118119 private $ l10nfactory ;
120+ private CappedMemoryCache $ internalCache ;
119121
120122 public function __construct (
121123 IDBConnection $ connection ,
@@ -142,6 +144,7 @@ public function __construct(
142144 $ this ->crypto = $ crypto ;
143145 // DIing IL10N results in a dependency loop
144146 $ this ->l10nfactory = $ factory ;
147+ $ this ->internalCache = new CappedMemoryCache ();
145148 }
146149
147150 /**
@@ -763,7 +766,12 @@ private function parseAccountData(IUser $user, $data): Account {
763766 }
764767
765768 public function getAccount (IUser $ user ): IAccount {
766- return $ this ->parseAccountData ($ user , $ this ->getUser ($ user ));
769+ if ($ this ->internalCache ->hasKey ($ user ->getUID ())) {
770+ return $ this ->internalCache ->get ($ user ->getUID ());
771+ }
772+ $ account = $ this ->parseAccountData ($ user , $ this ->getUser ($ user ));
773+ $ this ->internalCache ->set ($ user ->getUID (), $ account );
774+ return $ account ;
767775 }
768776
769777 public function updateAccount (IAccount $ account ): void {
@@ -813,5 +821,6 @@ public function updateAccount(IAccount $account): void {
813821 }
814822
815823 $ this ->updateUser ($ account ->getUser (), $ data , true );
824+ $ this ->internalCache ->set ($ account ->getUser ()->getUID (), $ account );
816825 }
817826}
0 commit comments