summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints/notes/timeline.ts
diff options
context:
space:
mode:
authoryukineko <27853966+hideki0403@users.noreply.github.com>2023-10-24 14:34:32 +0900
committerGitHub <noreply@github.com>2023-10-24 14:34:32 +0900
commit0c730968a363482a36f20ddec0a77eef1fd8639e (patch)
treecfa20b4e195cb5da146e5ce7fcad7ddf9c52d0a6 /packages/backend/src/server/api/endpoints/notes/timeline.ts
parentci: fix pullreq number may not get correctly (#12127) (diff)
downloadsharkey-0c730968a363482a36f20ddec0a77eef1fd8639e.tar.gz
sharkey-0c730968a363482a36f20ddec0a77eef1fd8639e.tar.bz2
sharkey-0c730968a363482a36f20ddec0a77eef1fd8639e.zip
fix: RedisへのTLキャッシュが有効の場合にHTL/LTL/STL/リストが空になることがある問題を修正 (#12088) (#12124)
* fix: RedisTimelineが有効の場合にHTLがリセットされた状態になる問題を修正 * add: CHANGELOG.md * fix: LTL, STLでもTLが空になることがある問題を修正 * update: CHANGELOG.md * fix: DBへのフォールバック時にwithRenotesが考慮されていないのを修正 * feat: リストにもDBフォールバックを実装 * fix: リストのDBフォールバック時の挙動を修正 --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
Diffstat (limited to 'packages/backend/src/server/api/endpoints/notes/timeline.ts')
-rw-r--r--packages/backend/src/server/api/endpoints/notes/timeline.ts24
1 files changed, 16 insertions, 8 deletions
diff --git a/packages/backend/src/server/api/endpoints/notes/timeline.ts b/packages/backend/src/server/api/endpoints/notes/timeline.ts
index c435fa7ec9..ac88c1f82b 100644
--- a/packages/backend/src/server/api/endpoints/notes/timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/timeline.ts
@@ -5,7 +5,7 @@
import { Brackets } from 'typeorm';
import { Inject, Injectable } from '@nestjs/common';
-import type { NotesRepository } from '@/models/_.js';
+import type { MiNote, NotesRepository } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { QueryService } from '@/core/QueryService.js';
import ActiveUsersChart from '@/core/chart/charts/active-users.js';
@@ -89,6 +89,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
let noteIds = await this.funoutTimelineService.get(ps.withFiles ? `homeTimelineWithFiles:${me.id}` : `homeTimeline:${me.id}`, untilId, sinceId);
noteIds = noteIds.slice(0, ps.limit);
+ let redisTimeline: MiNote[] = [];
+
if (noteIds.length > 0) {
const query = this.notesRepository.createQueryBuilder('note')
.where('note.id IN (:...noteIds)', { noteIds: noteIds })
@@ -99,9 +101,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('renote.user', 'renoteUser')
.leftJoinAndSelect('note.channel', 'channel');
- let timeline = await query.getMany();
+ redisTimeline = await query.getMany();
- timeline = timeline.filter(note => {
+ redisTimeline = redisTimeline.filter(note => {
if (note.userId === me.id) {
return true;
}
@@ -120,15 +122,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
return true;
});
- // TODO: フィルタした結果件数が足りなかった場合の対応
-
- timeline.sort((a, b) => a.id > b.id ? -1 : 1);
+ redisTimeline.sort((a, b) => a.id > b.id ? -1 : 1);
+ }
+ if (redisTimeline.length > 0) {
process.nextTick(() => {
this.activeUsersChart.read(me);
});
- return await this.noteEntityService.packMany(timeline, me);
+ return await this.noteEntityService.packMany(redisTimeline, me);
} else { // fallback to db
return await this.getFromDb({
untilId,
@@ -138,6 +140,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
includeRenotedMyNotes: ps.includeRenotedMyNotes,
includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
+ withRenotes: ps.withRenotes,
}, me);
}
} else {
@@ -149,12 +152,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
includeRenotedMyNotes: ps.includeRenotedMyNotes,
includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
+ withRenotes: ps.withRenotes,
}, me);
}
});
}
- private async getFromDb(ps: { untilId: string | null; sinceId: string | null; limit: number; includeMyRenotes: boolean; includeRenotedMyNotes: boolean; includeLocalRenotes: boolean; withFiles: boolean; }, me: MiLocalUser) {
+ private async getFromDb(ps: { untilId: string | null; sinceId: string | null; limit: number; includeMyRenotes: boolean; includeRenotedMyNotes: boolean; includeLocalRenotes: boolean; withFiles: boolean; withRenotes: boolean; }, me: MiLocalUser) {
const followees = await this.userFollowingService.getFollowees(me.id);
//#region Construct query
@@ -222,6 +226,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (ps.withFiles) {
query.andWhere('note.fileIds != \'{}\'');
}
+
+ if (ps.withRenotes === false) {
+ query.andWhere('note.renoteId IS NULL');
+ }
//#endregion
const timeline = await query.limit(ps.limit).getMany();