|
@@ -22,6 +22,7 @@ export default class Crowi {
|
|
|
|
|
|
|
|
this.users = [];
|
|
this.users = [];
|
|
|
this.userByName = {};
|
|
this.userByName = {};
|
|
|
|
|
+ this.userById = {};
|
|
|
this.draft = {};
|
|
this.draft = {};
|
|
|
|
|
|
|
|
this.recoverData();
|
|
this.recoverData();
|
|
@@ -34,6 +35,7 @@ export default class Crowi {
|
|
|
recoverData() {
|
|
recoverData() {
|
|
|
const keys = [
|
|
const keys = [
|
|
|
'userByName',
|
|
'userByName',
|
|
|
|
|
+ 'userById',
|
|
|
'users',
|
|
'users',
|
|
|
'draft',
|
|
'draft',
|
|
|
];
|
|
];
|
|
@@ -50,7 +52,7 @@ export default class Crowi {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fetchUsers () {
|
|
fetchUsers () {
|
|
|
- const interval = 1000*60*10; // 5min
|
|
|
|
|
|
|
+ const interval = 1000*60*15; // 15min
|
|
|
const currentTime = new Date();
|
|
const currentTime = new Date();
|
|
|
if (!this.localStorage.lastFetched && interval > currentTime - new Date(this.localStorage.lastFetched)) {
|
|
if (!this.localStorage.lastFetched && interval > currentTime - new Date(this.localStorage.lastFetched)) {
|
|
|
return ;
|
|
return ;
|
|
@@ -62,13 +64,18 @@ export default class Crowi {
|
|
|
this.localStorage.users = JSON.stringify(data.users);
|
|
this.localStorage.users = JSON.stringify(data.users);
|
|
|
|
|
|
|
|
let userByName = {};
|
|
let userByName = {};
|
|
|
|
|
+ let userById = {};
|
|
|
for (let i = 0; i < data.users.length; i++) {
|
|
for (let i = 0; i < data.users.length; i++) {
|
|
|
const user = data.users[i];
|
|
const user = data.users[i];
|
|
|
userByName[user.username] = user;
|
|
userByName[user.username] = user;
|
|
|
|
|
+ userById[user._id] = user;
|
|
|
}
|
|
}
|
|
|
this.userByName = userByName;
|
|
this.userByName = userByName;
|
|
|
this.localStorage.userByName = JSON.stringify(userByName);
|
|
this.localStorage.userByName = JSON.stringify(userByName);
|
|
|
|
|
|
|
|
|
|
+ this.userById = userById;
|
|
|
|
|
+ this.localStorage.userById = JSON.stringify(userById);
|
|
|
|
|
+
|
|
|
this.localStorage.lastFetched = new Date();
|
|
this.localStorage.lastFetched = new Date();
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
this.localStorage.removeItem('lastFetched');
|
|
this.localStorage.removeItem('lastFetched');
|
|
@@ -94,6 +101,14 @@ export default class Crowi {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ findUserById(userId) {
|
|
|
|
|
+ if (this.userById && this.userById[userId]) {
|
|
|
|
|
+ return this.userById[userId];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
findUser(username) {
|
|
findUser(username) {
|
|
|
if (this.userByName && this.userByName[username]) {
|
|
if (this.userByName && this.userByName[username]) {
|
|
|
return this.userByName[username];
|
|
return this.userByName[username];
|