From 4748f30214be2788776ed6f3a3900aef1afaa1e3 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Wed, 18 Oct 2023 13:20:20 +0200 Subject: [PATCH] [mastodon-client] Prevent updateUserInBackground from running excessively --- .../backend/src/server/api/mastodon/helpers/user.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/helpers/user.ts b/packages/backend/src/server/api/mastodon/helpers/user.ts index 55d171dff..06c28e3aa 100644 --- a/packages/backend/src/server/api/mastodon/helpers/user.ts +++ b/packages/backend/src/server/api/mastodon/helpers/user.ts @@ -528,9 +528,15 @@ export class UserHelpers { }); } - public static updateUserInBackground(user: User) { + public static async updateUserInBackground(user: User) { if (Users.isLocalUser(user)) return; - // noinspection JSIgnoredPromiseFromCall + if (user.lastFetchedAt != null && Date.now() - user.lastFetchedAt.getTime() < 1000 * 60 * 60 * 24) return; + + await Users.update(user.id, { + lastFetchedAt: new Date(), + }); + + // noinspection ES6MissingAwait updatePerson(user.uri!, undefined, undefined, user as IRemoteUser); }