mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-18 21:45:31 +09:00
perf(app): cut idle renderer CPU and unbounded memory growth (#1724)
This commit is contained in:
1 parent
b4a5eb77a8
commit
5660972c71
13 files changed
+453
-345
No files matched your search
@@ -55,6 +55,7 @@ function isPublicOnlyCurrentUserPayload(user: WireUser): boolean {
|
||||
|
||||
class Users {
|
||||
users: Record<string, User> = {};
|
||||
userCount = 0;
|
||||
|
||||
constructor() {
|
||||
makeAutoObservable(this, {}, {autoBind: true});
|
||||
@@ -98,6 +99,7 @@ class Users {
|
||||
this.users = {
|
||||
[currentUser.id]: userRecord,
|
||||
};
|
||||
this.userCount = 1;
|
||||
if (!userRecord.isClaimed()) {
|
||||
setTimeout(async () => {
|
||||
openClaimAccountModal();
|
||||
@@ -121,7 +123,18 @@ class Users {
|
||||
) {
|
||||
return;
|
||||
}
|
||||
this.users[user.id] = existingUser ? existingUser.withUpdates(user, options) : new User(user);
|
||||
this.storeUser(existingUser, existingUser ? existingUser.withUpdates(user, options) : new User(user));
|
||||
}
|
||||
|
||||
private storeUser(existingUser: User | undefined, nextUser: User): void {
|
||||
if (existingUser) {
|
||||
if (existingUser.equals(nextUser)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
this.userCount += 1;
|
||||
}
|
||||
this.users[nextUser.id] = nextUser;
|
||||
}
|
||||
|
||||
cacheUsers(
|
||||
@@ -137,14 +150,14 @@ class Users {
|
||||
if (user.id === this.currentUserId && existingUser && isPublicOnlyCurrentUserPayload(user)) {
|
||||
continue;
|
||||
}
|
||||
this.users[user.id] = existingUser ? existingUser.withUpdates(user) : new User(user);
|
||||
this.storeUser(existingUser, existingUser ? existingUser.withUpdates(user) : new User(user));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
subscribe(callback: () => void): () => void {
|
||||
return reaction(
|
||||
() => Object.keys(this.users).length,
|
||||
() => this.userCount,
|
||||
() => callback(),
|
||||
{fireImmediately: true},
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user