@@ -25,13 +25,14 @@ import { makeSingleton, Translate } from '@singletons';
25
25
import { CoreEvents , CoreEventSiteData , CoreEventUserDeletedData , CoreEventUserSuspendedData } from '@singletons/events' ;
26
26
import { CoreStatusWithWarningsWSResponse , CoreWSExternalWarning } from '@services/ws' ;
27
27
import { CoreError } from '@classes/errors/error' ;
28
- import { USERS_TABLE_NAME , CoreUserDBRecord } from './database/user' ;
28
+ import { USERS_CACHE_TABLE_NAME , CoreUserDBRecord } from './database/user' ;
29
29
import { CoreUrl } from '@singletons/url' ;
30
30
import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site' ;
31
31
import { CoreCacheUpdateFrequency , CoreConstants } from '@/core/constants' ;
32
32
import { CorePromiseUtils } from '@singletons/promise-utils' ;
33
33
import { CoreTextFormat } from '@singletons/text' ;
34
34
import { CORE_USER_PROFILE_REFRESHED , CORE_USER_PROFILE_PICTURE_UPDATED , CORE_USER_PARTICIPANTS_LIST_LIMIT } from '../constants' ;
35
+ import { CoreStoredCache } from '@classes/stored-cache' ;
35
36
36
37
declare module '@singletons/events' {
37
38
@@ -61,6 +62,7 @@ export class CoreUserProvider {
61
62
static readonly PARTICIPANTS_LIST_LIMIT = CORE_USER_PARTICIPANTS_LIST_LIMIT ;
62
63
63
64
protected logger : CoreLogger ;
65
+ protected userCache = new CoreStoredCache ( USERS_CACHE_TABLE_NAME ) ;
64
66
65
67
constructor ( ) {
66
68
this . logger = CoreLogger . getInstance ( 'CoreUserProvider' ) ;
@@ -160,7 +162,7 @@ export class CoreUserProvider {
160
162
161
163
await Promise . all ( [
162
164
this . invalidateUserCache ( userId , site . getId ( ) ) ,
163
- site . getDb ( ) . deleteRecords ( USERS_TABLE_NAME , { id : userId } ) ,
165
+ this . userCache . deleteEntry ( userId , site . getId ( ) ) ,
164
166
] ) ;
165
167
}
166
168
@@ -303,9 +305,7 @@ export class CoreUserProvider {
303
305
* @returns Promise resolve when the user is retrieved.
304
306
*/
305
307
protected async getUserFromLocalDb ( userId : number , siteId ?: string ) : Promise < CoreUserDBRecord > {
306
- const site = await CoreSites . getSite ( siteId ) ;
307
-
308
- return site . getDb ( ) . getRecord ( USERS_TABLE_NAME , { id : userId } ) ;
308
+ return await this . userCache . getEntry ( userId , siteId ) ;
309
309
}
310
310
311
311
/**
@@ -382,7 +382,8 @@ export class CoreUserProvider {
382
382
if ( 'country' in user && user . country ) {
383
383
user . country = CoreCountries . getCountryName ( user . country ) ;
384
384
}
385
- this . storeUser ( user . id , user . fullname , user . profileimageurl ) ;
385
+
386
+ this . storeUser ( user ) ;
386
387
387
388
return user ;
388
389
}
@@ -706,25 +707,26 @@ export class CoreUserProvider {
706
707
/**
707
708
* Store user basic information in local DB to be retrieved if the WS call fails.
708
709
*
709
- * @param userId User ID.
710
- * @param fullname User full name.
711
- * @param avatar User avatar URL.
710
+ * @param user User to store.
712
711
* @param siteId ID of the site. If not defined, use current site.
713
712
*/
714
- protected async storeUser ( userId : number , fullname : string , avatar ?: string , siteId ?: string ) : Promise < void > {
715
- if ( ! userId ) {
713
+ protected async storeUser ( user : CoreUserBasicData , siteId ?: string ) : Promise < void > {
714
+ if ( ! user . id ) {
716
715
return ;
717
716
}
718
717
719
- const site = await CoreSites . getSite ( siteId ) ;
720
-
718
+ // Filter and map data to store.
721
719
const userRecord : CoreUserDBRecord = {
722
- id : userId ,
723
- fullname : fullname ,
724
- profileimageurl : avatar ,
720
+ id : user . id ,
721
+ fullname : user . fullname ,
722
+ profileimageurl : user . profileimageurl ,
723
+ firstname : user . firstname ,
724
+ lastname : user . lastname ,
725
+ initials : user . initials ,
725
726
} ;
726
727
727
- await site . getDb ( ) . insertRecord ( USERS_TABLE_NAME , userRecord ) ;
728
+
729
+ await this . userCache . setEntry ( user . id , userRecord , siteId ) ;
728
730
}
729
731
730
732
/**
@@ -733,9 +735,8 @@ export class CoreUserProvider {
733
735
* @param users Users to store.
734
736
* @param siteId ID of the site. If not defined, use current site.
735
737
*/
736
- async storeUsers ( users : CoreUserBasicData [ ] , siteId ?: string ) : Promise < void > {
737
- await Promise . all ( users . map ( ( user ) =>
738
- this . storeUser ( Number ( user . id ) , user . fullname , user . profileimageurl , siteId ) ) ) ;
738
+ async storeUsers ( users : CoreUserDBRecord [ ] , siteId ?: string ) : Promise < void > {
739
+ await Promise . all ( users . map ( ( user ) => this . storeUser ( user , siteId ) ) ) ;
739
740
}
740
741
741
742
/**
@@ -853,7 +854,11 @@ export type CoreUserProfilePictureUpdatedData = {
853
854
export type CoreUserBasicData = {
854
855
id : number ; // ID of the user.
855
856
fullname : string ; // The fullname of the user.
856
- profileimageurl ?: string ; // User image profile URL - big version.
857
+ profileimageurl : string ; // User image profile URL - big version.
858
+ firstname ?: string ; // The first name(s) of the user.
859
+ lastname ?: string ; // The family name of the user.
860
+ lastaccess ?: number ;
861
+ initials ?: string ; // Initials.
857
862
} ;
858
863
859
864
/**
0 commit comments