Browse Source

Set usernames to cache on start

master
morethanwords 3 years ago
parent
commit
7db608a216
  1. 27
      src/lib/appManagers/appUsersManager.ts

27
src/lib/appManagers/appUsersManager.ts

@ -130,6 +130,7 @@ export class AppUsersManager { @@ -130,6 +130,7 @@ export class AppUsersManager {
const user = users[i];
if(user) {
this.users[user.id] = user;
this.setUserNameToCache(user);
}
}
}
@ -375,6 +376,20 @@ export class AppUsersManager { @@ -375,6 +376,20 @@ export class AppUsersManager {
apiUsers.forEach((user) => this.saveApiUser(user, override));
}
private setUserNameToCache(user: MTUser.user, oldUser?: MTUser.user) {
if(!oldUser || oldUser.username !== user.username) {
if(oldUser?.username) {
const oldSearchUsername = cleanUsername(oldUser.username);
delete this.usernames[oldSearchUsername];
}
if(user.username) {
const searchUsername = cleanUsername(user.username);
this.usernames[searchUsername] = user.id;
}
}
}
public saveApiUser(user: MTUser, override?: boolean) {
if(user._ === 'userEmpty') return;
@ -398,17 +413,7 @@ export class AppUsersManager { @@ -398,17 +413,7 @@ export class AppUsersManager {
// * exclude from state
// defineNotNumerableProperties(user, ['initials', 'num', 'rFirstName', 'rFullName', 'rPhone', 'sortName', 'sortStatus']);
if(!oldUser || oldUser.username !== user.username) {
if(oldUser?.username) {
const oldSearchUsername = cleanUsername(oldUser.username);
delete this.usernames[oldSearchUsername];
}
if(user.username) {
const searchUsername = cleanUsername(user.username);
this.usernames[searchUsername] = userId;
}
}
this.setUserNameToCache(user, oldUser);
if(!oldUser
|| oldUser.initials === undefined

Loading…
Cancel
Save