Просмотр исходного кода

update cache only when check logged in

yusuketk 6 лет назад
Родитель
Сommit
d2515fd987

+ 0 - 4
src/client/js/components/Admin/Users/UserTable.jsx

@@ -23,10 +23,6 @@ class UserTable extends React.Component {
     this.getUserStatusLabel = this.getUserStatusLabel.bind(this);
   }
 
-  async componentDidUpdate() {
-    this.props.appContainer.updateImageUrlCached();
-  }
-
   /**
    * return status label element by `userStatus`
    * @param {string} userStatus

+ 10 - 13
src/server/models/user.js

@@ -225,7 +225,6 @@ module.exports = function(crowi) {
 
   userSchema.methods.updateImage = async function(attachment) {
     this.imageAttachment = attachment;
-    this.imageUrlCached = await this.generateImageUrlCached();
     return this.save();
   };
 
@@ -241,12 +240,6 @@ module.exports = function(crowi) {
     }
 
     this.imageAttachment = undefined;
-    this.imageUrlCached = await this.generateImageUrlCached();
-    return this.save();
-  };
-
-  userSchema.methods.updateImageUrlCached = async function() {
-    this.imageUrlCached = await this.generateImageUrlCached();
     return this.save();
   };
 
@@ -254,17 +247,21 @@ module.exports = function(crowi) {
     if (this.isGravatarEnabled) {
       const email = this.email || '';
       const hash = md5(email.trim().toLowerCase());
-      return `https://gravatar.com/avatar/${hash}`;
+      this.imageUrlCached = `https://gravatar.com/avatar/${hash}`;
     }
-    if (this.image) {
-      return this.image;
+    else if (this.image) {
+      this.imageUrlCached = this.image;
     }
-    if (this.imageAttachment) {
+    else if (this.imageAttachment) {
       const Attachment = crowi.model('Attachment');
       const imageAttachment = await Attachment.findById(this.imageAttachment);
-      return imageAttachment.filePathProxied;
+      this.imageUrlCached = imageAttachment.filePathProxied;
+    }
+    else {
+      this.imageUrlCached = '/images/icons/user.svg';
     }
-    return '/images/icons/user.svg';
+
+    return this.save();
   };
 
   userSchema.methods.updateGoogleId = function(googleId, callback) {

+ 1 - 1
src/server/service/passport.js

@@ -855,7 +855,7 @@ class PassportService {
           throw new Error('user not found');
         }
         if (!user.imageUrlCached) {
-          await user.updateImageUrlCached();
+          await user.generateImageUrlCached();
         }
         done(null, user);
       }