From 7a9c869ac5163968120bfd28b72f397d7367bdf7 Mon Sep 17 00:00:00 2001 From: advplyr Date: Fri, 24 Nov 2023 14:27:32 -0600 Subject: [PATCH] Ignore sequelize hooks when updating user lastSeen on socket authentication --- server/SocketAuthority.js | 4 ++-- server/models/User.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/server/SocketAuthority.js b/server/SocketAuthority.js index 31012107..da17f5df 100644 --- a/server/SocketAuthority.js +++ b/server/SocketAuthority.js @@ -192,9 +192,9 @@ class SocketAuthority { this.adminEmitter('user_online', client.user.toJSONForPublic(this.Server.playbackSessionManager.sessions)) - // Update user lastSeen + // Update user lastSeen without firing sequelize bulk update hooks user.lastSeen = Date.now() - await Database.updateUser(user) + await Database.userModel.updateFromOld(user, false) const initialPayload = { userId: client.user.id, diff --git a/server/models/User.js b/server/models/User.js index 4c348f42..220c0c40 100644 --- a/server/models/User.js +++ b/server/models/User.js @@ -99,11 +99,13 @@ class User extends Model { * Update User from old user model * * @param {oldUser} oldUser + * @param {boolean} [hooks=true] Run before / after bulk update hooks? * @returns {Promise} */ - static updateFromOld(oldUser) { + static updateFromOld(oldUser, hooks = true) { const user = this.getFromOld(oldUser) return this.update(user, { + hooks: !!hooks, where: { id: user.id }