mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 10:34:17 +00:00
Try to avoid requesting user data multiple times
This commit is contained in:
parent
82745629bc
commit
ff514368c3
@ -51,8 +51,16 @@ class App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getUserById(userId) {
|
getUserById(userId) {
|
||||||
return new Promise((resolve, reject) => {
|
let promise;
|
||||||
if (userId in this.data.users) {resolve(this.users[userId]);}
|
|
||||||
|
if (userId in this.data.users) {
|
||||||
|
if (this.data.users[userId] instanceof Promise) {
|
||||||
|
return this.data.users[userId];
|
||||||
|
} else {
|
||||||
|
return new Promise((resolve, reject) => {resolve(userValue);});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
promise = new Promise((resolve, reject) => {
|
||||||
this.socket.emit('users.user.get', userId, response => {
|
this.socket.emit('users.user.get', userId, response => {
|
||||||
if (response.code === 200) {
|
if (response.code === 200) {
|
||||||
this.data.users[userId] = response.payload;
|
this.data.users[userId] = response.payload;
|
||||||
@ -62,12 +70,13 @@ class App {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
this.data.users[userId] = promise;
|
||||||
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
usersPatchHandler(patch) {
|
usersPatchHandler(patch) {
|
||||||
let listener;
|
let listener;
|
||||||
|
|
||||||
console.log(patch);
|
|
||||||
this.data = jsonpatch.apply_patch(this.data, patch);
|
this.data = jsonpatch.apply_patch(this.data, patch);
|
||||||
for (listener of this.eventListeners['users.patch']) {listener(patch);}
|
for (listener of this.eventListeners['users.patch']) {listener(patch);}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user