mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-25 11:27:31 -07:00
[mastodon-api] Only wait up to 1500 ms for mentions to update on /accounts/update_credentials
This commit is contained in:
parent
b8bd0c9f3b
commit
998bb1ae08
2 changed files with 7 additions and 1 deletions
5
packages/backend/src/prelude/promise.ts
Normal file
5
packages/backend/src/prelude/promise.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
// Returns T if promise settles before timeout, otherwise returns void, finishing execution in the background.
|
||||||
|
export async function promiseEarlyReturn<T>(promise: Promise<T>, after: number): Promise<T | void> {
|
||||||
|
const timer: Promise<void> = new Promise((res) => setTimeout(() => res(undefined), after));
|
||||||
|
return Promise.race([promise, timer]);
|
||||||
|
}
|
|
@ -43,6 +43,7 @@ import { MastoApiError } from "@/server/api/mastodon/middleware/catch-errors.js"
|
||||||
import { MastoContext } from "@/server/api/mastodon/index.js";
|
import { MastoContext } from "@/server/api/mastodon/index.js";
|
||||||
import { resolveUser } from "@/remote/resolve-user.js";
|
import { resolveUser } from "@/remote/resolve-user.js";
|
||||||
import { updatePerson } from "@/remote/activitypub/models/person.js";
|
import { updatePerson } from "@/remote/activitypub/models/person.js";
|
||||||
|
import { promiseEarlyReturn } from "@/prelude/promise.js";
|
||||||
|
|
||||||
export type AccountCache = {
|
export type AccountCache = {
|
||||||
locks: AsyncLock;
|
locks: AsyncLock;
|
||||||
|
@ -197,7 +198,7 @@ export class UserHelpers {
|
||||||
if (Object.keys(updates).length > 0) await Users.update(user.id, updates);
|
if (Object.keys(updates).length > 0) await Users.update(user.id, updates);
|
||||||
if (Object.keys(profileUpdates).length > 0) {
|
if (Object.keys(profileUpdates).length > 0) {
|
||||||
await UserProfiles.update({ userId: user.id }, profileUpdates);
|
await UserProfiles.update({ userId: user.id }, profileUpdates);
|
||||||
await UserProfiles.updateMentions(user.id);
|
await promiseEarlyReturn(UserProfiles.updateMentions(user.id), 1500);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.verifyCredentials(ctx);
|
return this.verifyCredentials(ctx);
|
||||||
|
|
Loading…
Reference in a new issue