summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-06-02 17:34:35 -0400
committerHazelnoot <acomputerdog@gmail.com>2025-06-02 17:34:35 -0400
commit51d9b1c8c5a6a3f5378203384f1972417b1a34bf (patch)
tree7798a022324e35282de230967db39abf702922c6 /packages/backend/src/server/api/endpoints
parentuse generateMatchingHostQuery in bubble-timeline.ts (diff)
downloadsharkey-51d9b1c8c5a6a3f5378203384f1972417b1a34bf.tar.gz
sharkey-51d9b1c8c5a6a3f5378203384f1972417b1a34bf.tar.bz2
sharkey-51d9b1c8c5a6a3f5378203384f1972417b1a34bf.zip
fetch followings asynchronously in bubble-timeline.ts
Diffstat (limited to 'packages/backend/src/server/api/endpoints')
-rw-r--r--packages/backend/src/server/api/endpoints/notes/bubble-timeline.ts25
1 files changed, 14 insertions, 11 deletions
diff --git a/packages/backend/src/server/api/endpoints/notes/bubble-timeline.ts b/packages/backend/src/server/api/endpoints/notes/bubble-timeline.ts
index afc571d1f4..bbd41ca99f 100644
--- a/packages/backend/src/server/api/endpoints/notes/bubble-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/bubble-timeline.ts
@@ -76,7 +76,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.btlDisabled);
}
- const followings = me ? await this.cacheService.userFollowingsCache.fetch(me.id) : undefined;
+ // Run this asynchronously - we will await it after the query completes.
+ // Catch-suppression is needed to avoid "unhandled rejection" if the query throws.
+ const followingsPromise = me ? this.cacheService.userFollowingsCache.fetch(me.id).catch(() => null) : null;
//#region Construct query
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
@@ -122,16 +124,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
let timeline = await query.limit(ps.limit).getMany();
- timeline = timeline.filter(note => {
- if (note.user?.isSilenced) {
- if (!me) return false;
- if (!followings) return false;
- if (note.userId !== me.id) {
- return followings[note.userId];
- }
- }
- return true;
- });
+ const followings = await followingsPromise;
+ if (me && followings) {
+ timeline = timeline.filter(note => {
+ // Allow my own notes
+ if (note.userId === me.id) return true;
+ // Allow if not silenced
+ if (!note.user?.isSilenced) return true;
+ // Allow if following
+ return followings[note.userId];
+ });
+ }
if (me) {
process.nextTick(() => {