summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api
diff options
context:
space:
mode:
authorHazelnoot <acomputerdog@gmail.com>2025-06-04 12:40:13 +0000
committerHazelnoot <acomputerdog@gmail.com>2025-06-04 12:40:13 +0000
commitdae544b353ebbc6edd85c032786b9901807460e8 (patch)
treef8495c993b0c29f911220ade7df8a5f3f076e811 /packages/backend/src/server/api
parentmerge: Fix error caused by activity type confusion (!1090) (diff)
parentrestore join to note.channel in channel/timeline.ts (diff)
downloadsharkey-dae544b353ebbc6edd85c032786b9901807460e8.tar.gz
sharkey-dae544b353ebbc6edd85c032786b9901807460e8.tar.bz2
sharkey-dae544b353ebbc6edd85c032786b9901807460e8.zip
merge: Rework queries and add indexes to improve timeline performance (!1091)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/1091 Approved-by: dakkar <dakkar@thenautilus.net> Approved-by: Marie <github@yuugi.dev>
Diffstat (limited to 'packages/backend/src/server/api')
-rw-r--r--packages/backend/src/server/api/endpoints/antennas/notes.ts18
-rw-r--r--packages/backend/src/server/api/endpoints/channels/timeline.ts27
-rw-r--r--packages/backend/src/server/api/endpoints/notes/bubble-timeline.ts70
-rw-r--r--packages/backend/src/server/api/endpoints/notes/following.ts16
-rw-r--r--packages/backend/src/server/api/endpoints/notes/global-timeline.ts38
-rw-r--r--packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts57
-rw-r--r--packages/backend/src/server/api/endpoints/notes/local-timeline.ts46
-rw-r--r--packages/backend/src/server/api/endpoints/notes/mentions.ts30
-rw-r--r--packages/backend/src/server/api/endpoints/notes/search-by-tag.ts3
-rw-r--r--packages/backend/src/server/api/endpoints/notes/timeline.ts56
-rw-r--r--packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts70
-rw-r--r--packages/backend/src/server/api/endpoints/roles/notes.ts12
-rw-r--r--packages/backend/src/server/api/stream/channel.ts26
-rw-r--r--packages/backend/src/server/api/stream/channels/bubble-timeline.ts34
-rw-r--r--packages/backend/src/server/api/stream/channels/global-timeline.ts28
-rw-r--r--packages/backend/src/server/api/stream/channels/home-timeline.ts20
-rw-r--r--packages/backend/src/server/api/stream/channels/hybrid-timeline.ts18
-rw-r--r--packages/backend/src/server/api/stream/channels/local-timeline.ts31
-rw-r--r--packages/backend/src/server/api/stream/channels/main.ts8
-rw-r--r--packages/backend/src/server/api/stream/channels/role-timeline.ts22
-rw-r--r--packages/backend/src/server/api/stream/channels/user-list.ts33
21 files changed, 309 insertions, 354 deletions
diff --git a/packages/backend/src/server/api/endpoints/antennas/notes.ts b/packages/backend/src/server/api/endpoints/antennas/notes.ts
index 7e79f0dccc..1abeee53d2 100644
--- a/packages/backend/src/server/api/endpoints/antennas/notes.ts
+++ b/packages/backend/src/server/api/endpoints/antennas/notes.ts
@@ -14,6 +14,7 @@ import { IdService } from '@/core/IdService.js';
import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
import { GlobalEventService } from '@/core/GlobalEventService.js';
import { trackPromise } from '@/misc/promise-tracker.js';
+import ActiveUsersChart from '@/core/chart/charts/active-users.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -75,6 +76,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private queryService: QueryService,
private fanoutTimelineService: FanoutTimelineService,
private globalEventService: GlobalEventService,
+ private readonly activeUsersChart: ActiveUsersChart,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
@@ -106,13 +108,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
return [];
}
- const query = this.notesRepository.createQueryBuilder('note')
+ const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
+ ps.sinceId, ps.untilId)
.where('note.id IN (:...noteIds)', { noteIds: noteIds })
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ .leftJoinAndSelect('reply.user', 'replyUser', 'replyUser.id = note.replyUserId')
+ .leftJoinAndSelect('renote.user', 'renoteUser', 'renoteUser.id = note.renoteUserId');
// NOTE: センシティブ除外の設定はこのエンドポイントでは無視する。
// https://github.com/misskey-dev/misskey/pull/15346#discussion_r1929950255
@@ -124,11 +127,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
const notes = await query.getMany();
- if (sinceId != null && untilId == null) {
- notes.sort((a, b) => a.id < b.id ? -1 : 1);
- } else {
- notes.sort((a, b) => a.id > b.id ? -1 : 1);
- }
+
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
return await this.noteEntityService.packMany(notes, me);
});
diff --git a/packages/backend/src/server/api/endpoints/channels/timeline.ts b/packages/backend/src/server/api/endpoints/channels/timeline.ts
index 99ae1c2211..b7152130d5 100644
--- a/packages/backend/src/server/api/endpoints/channels/timeline.ts
+++ b/packages/backend/src/server/api/endpoints/channels/timeline.ts
@@ -96,7 +96,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.noSuchChannel);
}
- if (me) this.activeUsersChart.read(me);
+ if (me) {
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
+ }
if (!this.serverSettings.enableFanoutTimeline) {
return await this.noteEntityService.packMany(await this.getFromDb({ untilId, sinceId, limit: ps.limit, channelId: channel.id, withFiles: ps.withFiles, withRenotes: ps.withRenotes }, me), me);
@@ -133,8 +137,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser')
+ .leftJoinAndSelect('reply.user', 'replyUser', 'replyUser.id = note.replyUserId')
+ .leftJoinAndSelect('renote.user', 'renoteUser', 'renoteUser.id = note.renoteUserId')
.leftJoinAndSelect('note.channel', 'channel');
this.queryService.generateBlockedHostQueryForNote(query);
@@ -142,22 +146,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (me) {
this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
- this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
- }
-
- if (ps.withRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere(new Brackets(qb => {
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- }));
- }));
}
if (ps.withFiles) {
query.andWhere('note.fileIds != \'{}\'');
}
+
+ if (!ps.withRenotes) {
+ this.queryService.generateExcludedRenotesQueryForNotes(query);
+ } else if (me) {
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ }
//#endregion
return await query.limit(ps.limit).getMany();
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 17c9b31c90..5f16351b20 100644
--- a/packages/backend/src/server/api/endpoints/notes/bubble-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/bubble-timeline.ts
@@ -1,13 +1,16 @@
+/*
+ * SPDX-FileCopyrightText: Marie and other Sharkey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
import { Inject, Injectable } from '@nestjs/common';
-import { Brackets } from 'typeorm';
-import type { NotesRepository, MiMeta } from '@/models/_.js';
+import type { NotesRepository } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { QueryService } from '@/core/QueryService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import ActiveUsersChart from '@/core/chart/charts/active-users.js';
import { DI } from '@/di-symbols.js';
import { RoleService } from '@/core/RoleService.js';
-import { CacheService } from '@/core/CacheService.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -56,9 +59,6 @@ export const paramDef = {
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
- @Inject(DI.meta)
- private serverSettings: MiMeta,
-
@Inject(DI.notesRepository)
private notesRepository: NotesRepository,
@@ -66,7 +66,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private queryService: QueryService,
private roleService: RoleService,
private activeUsersChart: ActiveUsersChart,
- private cacheService: CacheService,
) {
super(meta, paramDef, async (ps, me) => {
const policies = await this.roleService.getUserPolicies(me ? me.id : null);
@@ -74,27 +73,33 @@ 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;
-
//#region Construct query
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
.andWhere('note.visibility = \'public\'')
.andWhere('note.channelId IS NULL')
.andWhere('note.userHost IS NOT NULL')
- .andWhere('userInstance.isBubbled = true') // This comes from generateBlockedHostQueryForNote below
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ .leftJoinAndSelect('reply.user', 'replyUser', 'replyUser.id = note.replyUserId')
+ .leftJoinAndSelect('renote.user', 'renoteUser', 'renoteUser.id = note.renoteUserId');
+
+ // This subquery mess teaches postgres how to use the right indexes.
+ // Using WHERE or ON conditions causes a fallback to full sequence scan, which times out.
+ // Important: don't use a query builder here or TypeORM will get confused and stop quoting column names! (known, unfixed bug apparently)
+ query
+ .leftJoin('(select "host" from "instance" where "isBubbled" = true)', 'bubbleInstance', '"bubbleInstance"."host" = "note"."userHost"')
+ .andWhere('"bubbleInstance" IS NOT NULL');
+ this.queryService
+ .leftJoinInstance(query, 'note.userInstance', 'userInstance', '"userInstance"."host" = "bubbleInstance"."host"');
- this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
- if (me) this.queryService.generateMutedUserQueryForNotes(query, me);
- if (me) this.queryService.generateBlockedUserQueryForNotes(query, me);
- if (me) this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
- if (!me) query.andWhere('user.requireSigninToViewContents = false');
+ this.queryService.generateSilencedUserQueryForNotes(query, me);
+ if (me) {
+ this.queryService.generateMutedUserQueryForNotes(query, me);
+ this.queryService.generateBlockedUserQueryForNotes(query, me);
+ }
if (ps.withFiles) {
query.andWhere('note.fileIds != \'{}\'');
@@ -103,34 +108,19 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (!ps.withBots) query.andWhere('user.isBot = FALSE');
if (!ps.withRenotes) {
- query.andWhere(new Brackets(qb => qb
- .orWhere('note.renoteId IS NULL')
- .orWhere('note.text IS NOT NULL')
- .orWhere('note.cw IS NOT NULL')
- .orWhere('note.replyId IS NOT NULL')
- .orWhere('note.hasPoll = false')
- .orWhere('note.fileIds != \'{}\'')));
+ this.queryService.generateExcludedRenotesQueryForNotes(query);
+ } else if (me) {
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
}
//#endregion
- 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 timeline = await query.limit(ps.limit).getMany();
- process.nextTick(() => {
- if (me) {
+ if (me) {
+ process.nextTick(() => {
this.activeUsersChart.read(me);
- }
- });
+ });
+ }
return await this.noteEntityService.packMany(timeline, me);
});
diff --git a/packages/backend/src/server/api/endpoints/notes/following.ts b/packages/backend/src/server/api/endpoints/notes/following.ts
index 088b172ba4..ac26dbbbc8 100644
--- a/packages/backend/src/server/api/endpoints/notes/following.ts
+++ b/packages/backend/src/server/api/endpoints/notes/following.ts
@@ -12,6 +12,7 @@ import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { DI } from '@/di-symbols.js';
import { QueryService } from '@/core/QueryService.js';
import { ApiError } from '@/server/api/error.js';
+import ActiveUsersChart from '@/core/chart/charts/active-users.js';
export const meta = {
tags: ['notes'],
@@ -76,8 +77,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
@Inject(DI.notesRepository)
private notesRepository: NotesRepository,
- private noteEntityService: NoteEntityService,
- private queryService: QueryService,
+ private readonly noteEntityService: NoteEntityService,
+ private readonly queryService: QueryService,
+ private readonly activeUsersChart: ActiveUsersChart,
) {
super(meta, paramDef, async (ps, me) => {
if (ps.includeReplies && ps.filesOnly) throw new ApiError(meta.errors.bothWithRepliesAndWithFiles);
@@ -128,8 +130,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser')
+ .leftJoinAndSelect('reply.user', 'replyUser', 'replyUser.id = note.replyUserId')
+ .leftJoinAndSelect('renote.user', 'renoteUser', 'renoteUser.id = note.renoteUserId')
// Exclude channel notes
.andWhere({ channelId: IsNull() })
@@ -157,11 +159,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Support pagination
this.queryService
.makePaginationQuery(query, ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
- .orderBy('note.id', 'DESC')
.take(ps.limit);
// Query and return the next page
const notes = await query.getMany();
+
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
+
return await this.noteEntityService.packMany(notes, me, { skipHide: true });
});
}
diff --git a/packages/backend/src/server/api/endpoints/notes/global-timeline.ts b/packages/backend/src/server/api/endpoints/notes/global-timeline.ts
index e82d9ca7af..6ebb3c1676 100644
--- a/packages/backend/src/server/api/endpoints/notes/global-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/global-timeline.ts
@@ -12,7 +12,6 @@ import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import ActiveUsersChart from '@/core/chart/charts/active-users.js';
import { DI } from '@/di-symbols.js';
import { RoleService } from '@/core/RoleService.js';
-import { CacheService } from '@/core/CacheService.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -68,7 +67,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private queryService: QueryService,
private roleService: RoleService,
private activeUsersChart: ActiveUsersChart,
- private cacheService: CacheService,
) {
super(meta, paramDef, async (ps, me) => {
const policies = await this.roleService.getUserPolicies(me ? me.id : null);
@@ -76,8 +74,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.gtlDisabled);
}
- const followings = me ? await this.cacheService.userFollowingsCache.fetch(me.id) : {};
-
//#region Construct query
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
@@ -86,15 +82,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ .leftJoinAndSelect('reply.user', 'replyUser', 'replyUser.id = note.replyUserId')
+ .leftJoinAndSelect('renote.user', 'renoteUser', 'renoteUser.id = note.renoteUserId');
this.queryService.generateBlockedHostQueryForNote(query);
-
+ this.queryService.generateSilencedUserQueryForNotes(query, me);
if (me) {
this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
- this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
}
if (ps.withFiles) {
@@ -103,29 +98,20 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (!ps.withBots) query.andWhere('user.isBot = FALSE');
- if (ps.withRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.where('note.renoteId IS NULL');
- qb.orWhere(new Brackets(qb => {
- qb.where('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- }));
- }));
+ if (!ps.withRenotes) {
+ this.queryService.generateExcludedRenotesQueryForNotes(query);
+ } else if (me) {
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
}
//#endregion
- let timeline = await query.limit(ps.limit).getMany();
+ const timeline = await query.limit(ps.limit).getMany();
- timeline = timeline.filter(note => {
- if (note.user?.isSilenced && me && followings && note.userId !== me.id && !followings[note.userId]) return false;
- return true;
- });
-
- process.nextTick(() => {
- if (me) {
+ if (me) {
+ process.nextTick(() => {
this.activeUsersChart.read(me);
- }
- });
+ });
+ }
return await this.noteEntityService.packMany(timeline, me);
});
diff --git a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
index 6461a2e33f..083da9090f 100644
--- a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
@@ -66,9 +66,6 @@ export const paramDef = {
sinceDate: { type: 'integer' },
untilDate: { type: 'integer' },
allowPartial: { type: 'boolean', default: false }, // true is recommended but for compatibility false by default
- includeMyRenotes: { type: 'boolean', default: true },
- includeRenotedMyNotes: { type: 'boolean', default: true },
- includeLocalRenotes: { type: 'boolean', default: true },
withFiles: { type: 'boolean', default: false },
withRenotes: { type: 'boolean', default: true },
withReplies: { type: 'boolean', default: false },
@@ -114,12 +111,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId,
sinceId,
limit: ps.limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withReplies: ps.withReplies,
withBots: ps.withBots,
+ withRenotes: ps.withRenotes,
}, me);
process.nextTick(() => {
@@ -178,12 +173,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId,
sinceId,
limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withReplies: ps.withReplies,
withBots: ps.withBots,
+ withRenotes: ps.withRenotes,
}, me),
});
@@ -199,12 +192,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId: string | null,
sinceId: string | null,
limit: number,
- includeMyRenotes: boolean,
- includeRenotedMyNotes: boolean,
- includeLocalRenotes: boolean,
withFiles: boolean,
withReplies: boolean,
withBots: boolean,
+ withRenotes: boolean,
}, me: MiLocalUser) {
const followees = await this.userFollowingService.getFollowees(me.id);
const followingChannels = await this.channelFollowingsRepository.find({
@@ -227,8 +218,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ .leftJoinAndSelect('reply.user', 'replyUser', 'replyUser.id = note.replyUserId')
+ .leftJoinAndSelect('renote.user', 'renoteUser', 'renoteUser.id = note.renoteUserId');
if (followingChannels.length > 0) {
const followingChannelIds = followingChannels.map(x => x.followeeId);
@@ -255,45 +246,21 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
+ this.queryService.generateSilencedUserQueryForNotes(query, me);
this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
- this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
-
- if (ps.includeMyRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.userId != :meId', { meId: me.id });
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
-
- if (ps.includeRenotedMyNotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteUserId != :meId', { meId: me.id });
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
-
- if (ps.includeLocalRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteUserHost IS NOT NULL');
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
if (ps.withFiles) {
query.andWhere('note.fileIds != \'{}\'');
}
if (!ps.withBots) query.andWhere('user.isBot = FALSE');
+
+ if (!ps.withRenotes) {
+ this.queryService.generateExcludedRenotesQueryForNotes(query);
+ } else {
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ }
//#endregion
return await query.limit(ps.limit).getMany();
diff --git a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts
index f55853f3f3..360528eaed 100644
--- a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts
@@ -103,13 +103,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
withFiles: ps.withFiles,
withReplies: ps.withReplies,
withBots: ps.withBots,
+ withRenotes: ps.withRenotes,
}, me);
- process.nextTick(() => {
- if (me) {
+ if (me) {
+ process.nextTick(() => {
this.activeUsersChart.read(me);
- }
- });
+ });
+ }
return await this.noteEntityService.packMany(timeline, me);
}
@@ -136,14 +137,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
withFiles: ps.withFiles,
withReplies: ps.withReplies,
withBots: ps.withBots,
+ withRenotes: ps.withRenotes,
}, me),
});
- process.nextTick(() => {
- if (me) {
+ if (me) {
+ process.nextTick(() => {
this.activeUsersChart.read(me);
- }
- });
+ });
+ }
return timeline;
});
@@ -156,26 +158,38 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
withFiles: boolean,
withReplies: boolean,
withBots: boolean,
+ withRenotes: boolean,
}, me: MiLocalUser | null) {
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
ps.sinceId, ps.untilId)
- .andWhere('(note.visibility = \'public\') AND (note.userHost IS NULL) AND (note.channelId IS NULL)')
+ .andWhere('note.visibility = \'public\'')
+ .andWhere('note.channelId IS NULL')
+ .andWhere('note.userHost IS NULL')
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ .leftJoinAndSelect('reply.user', 'replyUser', 'replyUser.id = note.replyUserId')
+ .leftJoinAndSelect('renote.user', 'renoteUser', 'renoteUser.id = note.renoteUserId');
- this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
- if (me) this.queryService.generateMutedUserQueryForNotes(query, me);
- if (me) this.queryService.generateBlockedUserQueryForNotes(query, me);
- if (me) this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ this.queryService.generateSilencedUserQueryForNotes(query, me);
+ if (me) {
+ this.queryService.generateMutedUserQueryForNotes(query, me);
+ this.queryService.generateBlockedUserQueryForNotes(query, me);
+ }
if (ps.withFiles) {
query.andWhere('note.fileIds != \'{}\'');
}
+ if (!ps.withBots) query.andWhere('user.isBot = FALSE');
+
+ if (!ps.withRenotes) {
+ this.queryService.generateExcludedRenotesQueryForNotes(query);
+ } else if (me) {
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ }
+
if (!ps.withReplies) {
query.andWhere(new Brackets(qb => {
qb
@@ -188,8 +202,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}));
}
- if (!ps.withBots) query.andWhere('user.isBot = FALSE');
-
return await query.limit(ps.limit).getMany();
}
}
diff --git a/packages/backend/src/server/api/endpoints/notes/mentions.ts b/packages/backend/src/server/api/endpoints/notes/mentions.ts
index 269b57366c..7c54bc69ab 100644
--- a/packages/backend/src/server/api/endpoints/notes/mentions.ts
+++ b/packages/backend/src/server/api/endpoints/notes/mentions.ts
@@ -10,6 +10,7 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { QueryService } from '@/core/QueryService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { DI } from '@/di-symbols.js';
+import ActiveUsersChart from '@/core/chart/charts/active-users.js';
export const meta = {
tags: ['notes'],
@@ -57,43 +58,44 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private noteEntityService: NoteEntityService,
private queryService: QueryService,
+ private readonly activeUsersChart: ActiveUsersChart,
) {
super(meta, paramDef, async (ps, me) => {
- const followingQuery = this.followingsRepository.createQueryBuilder('following')
- .select('following.followeeId')
- .where('following.followerId = :followerId', { followerId: me.id });
-
- const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
- .andWhere(new Brackets(qb => {
- qb // このmeIdAsListパラメータはqueryServiceのgenerateVisibilityQueryでセットされる
- .where(':meIdAsList <@ note.mentions')
- .orWhere(':meIdAsList <@ note.visibleUserIds');
- }))
+ const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
+ ps.sinceId, ps.untilId)
+ .andWhere(new Brackets(qb => qb
+ .orWhere(':meId = ANY (note.mentions)')
+ .orWhere(':meId = ANY (note.visibleUserIds)')))
+ .setParameters({ meId: me.id })
// Avoid scanning primary key index
.orderBy('CONCAT(note.id)', 'DESC')
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ .leftJoinAndSelect('reply.user', 'replyUser', 'replyUser.id = note.replyUserId')
+ .leftJoinAndSelect('renote.user', 'renoteUser', 'renoteUser.id = note.renoteUserId');
this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateMutedNoteThreadQuery(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
if (ps.visibility) {
query.andWhere('note.visibility = :visibility', { visibility: ps.visibility });
}
if (ps.following) {
- query.andWhere(`((note.userId IN (${ followingQuery.getQuery() })) OR (note.userId = :meId))`, { meId: me.id });
- query.setParameters(followingQuery.getParameters());
+ this.queryService.andFollowingUser(query, ':meId', 'note.userId');
}
const mentions = await query.limit(ps.limit).getMany();
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
+
return await this.noteEntityService.packMany(mentions, me);
});
}
diff --git a/packages/backend/src/server/api/endpoints/notes/search-by-tag.ts b/packages/backend/src/server/api/endpoints/notes/search-by-tag.ts
index 5c1ab0fb78..01bedd9b1d 100644
--- a/packages/backend/src/server/api/endpoints/notes/search-by-tag.ts
+++ b/packages/backend/src/server/api/endpoints/notes/search-by-tag.ts
@@ -96,7 +96,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (!this.serverSettings.enableBotTrending) query.andWhere('user.isBot = FALSE');
- this.queryService.generateBlockedHostQueryForNote(query, undefined, false);
+ this.queryService.generateBlockedHostQueryForNote(query);
+ this.queryService.generateSilencedUserQueryForNotes(query, me);
if (me) this.queryService.generateMutedUserQueryForNotes(query, me);
if (me) this.queryService.generateBlockedUserQueryForNotes(query, me);
if (me) this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
diff --git a/packages/backend/src/server/api/endpoints/notes/timeline.ts b/packages/backend/src/server/api/endpoints/notes/timeline.ts
index a2dfa7fdac..a23a61373e 100644
--- a/packages/backend/src/server/api/endpoints/notes/timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/timeline.ts
@@ -49,9 +49,6 @@ export const paramDef = {
sinceDate: { type: 'integer' },
untilDate: { type: 'integer' },
allowPartial: { type: 'boolean', default: false }, // true is recommended but for compatibility false by default
- includeMyRenotes: { type: 'boolean', default: true },
- includeRenotedMyNotes: { type: 'boolean', default: true },
- includeLocalRenotes: { type: 'boolean', default: true },
withFiles: { type: 'boolean', default: false },
withRenotes: { type: 'boolean', default: true },
withBots: { type: 'boolean', default: true },
@@ -88,9 +85,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId,
sinceId,
limit: ps.limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withRenotes: ps.withRenotes,
withBots: ps.withBots,
@@ -131,9 +125,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId,
sinceId,
limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withRenotes: ps.withRenotes,
withBots: ps.withBots,
@@ -148,7 +139,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
});
}
- private async getFromDb(ps: { untilId: string | null; sinceId: string | null; limit: number; includeMyRenotes: boolean; includeRenotedMyNotes: boolean; includeLocalRenotes: boolean; withFiles: boolean; withRenotes: boolean; withBots: boolean; }, me: MiLocalUser) {
+ private async getFromDb(ps: { untilId: string | null; sinceId: string | null; limit: number; withFiles: boolean; withRenotes: boolean; withBots: boolean; }, me: MiLocalUser) {
const followees = await this.userFollowingService.getFollowees(me.id);
const followingChannels = await this.channelFollowingsRepository.find({
where: {
@@ -161,8 +152,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ .leftJoinAndSelect('reply.user', 'replyUser', 'replyUser.id = note.replyUserId')
+ .leftJoinAndSelect('renote.user', 'renoteUser', 'renoteUser.id = note.renoteUserId');
if (followees.length > 0 && followingChannels.length > 0) {
// ユーザー・チャンネルともにフォローあり
@@ -212,47 +203,18 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.queryService.generateBlockedHostQueryForNote(query);
this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
- this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
-
- if (ps.includeMyRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.userId != :meId', { meId: me.id });
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
-
- if (ps.includeRenotedMyNotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteUserId != :meId', { meId: me.id });
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
-
- if (ps.includeLocalRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteUserHost IS NOT NULL');
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
if (ps.withFiles) {
query.andWhere('note.fileIds != \'{}\'');
}
- if (ps.withRenotes === false) {
- query.andWhere('note.renoteId IS NULL');
- }
-
if (!ps.withBots) query.andWhere('user.isBot = FALSE');
+
+ if (!ps.withRenotes) {
+ this.queryService.generateExcludedRenotesQueryForNotes(query);
+ } else if (me) {
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ }
//#endregion
return await query.limit(ps.limit).getMany();
diff --git a/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts b/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts
index 60f18a09b0..8872672b67 100644
--- a/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts
@@ -57,9 +57,6 @@ export const paramDef = {
sinceDate: { type: 'integer' },
untilDate: { type: 'integer' },
allowPartial: { type: 'boolean', default: false }, // true is recommended but for compatibility false by default
- includeMyRenotes: { type: 'boolean', default: true },
- includeRenotedMyNotes: { type: 'boolean', default: true },
- includeLocalRenotes: { type: 'boolean', default: true },
withRenotes: { type: 'boolean', default: true },
withFiles: {
type: 'boolean',
@@ -109,14 +106,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId,
sinceId,
limit: ps.limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withRenotes: ps.withRenotes,
}, me);
- this.activeUsersChart.read(me);
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
return await this.noteEntityService.packMany(timeline, me);
}
@@ -135,15 +131,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId,
sinceId,
limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withRenotes: ps.withRenotes,
}, me),
});
- this.activeUsersChart.read(me);
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
return timeline;
});
@@ -153,9 +148,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId: string | null,
sinceId: string | null,
limit: number,
- includeMyRenotes: boolean,
- includeRenotedMyNotes: boolean,
- includeLocalRenotes: boolean,
withFiles: boolean,
withRenotes: boolean,
}, me: MiLocalUser) {
@@ -165,8 +157,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser')
+ .leftJoinAndSelect('reply.user', 'replyUser', 'replyUser.id = note.replyUserId')
+ .leftJoinAndSelect('renote.user', 'renoteUser', 'renoteUser.id = note.renoteUserId')
.andWhere('userListMemberships.userListId = :userListId', { userListId: list.id })
.andWhere('note.channelId IS NULL') // チャンネルノートではない
.andWhere(new Brackets(qb => {
@@ -193,51 +185,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.queryService.generateBlockedHostQueryForNote(query);
this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
- this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
-
- if (ps.includeMyRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.userId != :meId', { meId: me.id });
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
-
- if (ps.includeRenotedMyNotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteUserId != :meId', { meId: me.id });
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
- if (ps.includeLocalRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteUserHost IS NOT NULL');
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
+ if (ps.withFiles) {
+ query.andWhere('note.fileIds != \'{}\'');
}
- if (ps.withRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere(new Brackets(qb => {
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- }));
- }));
+ if (!ps.withRenotes) {
+ this.queryService.generateExcludedRenotesQueryForNotes(query);
+ } else if (me) {
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
}
- if (ps.withFiles) {
- query.andWhere('note.fileIds != \'{}\'');
- }
//#endregion
return await query.limit(ps.limit).getMany();
diff --git a/packages/backend/src/server/api/endpoints/roles/notes.ts b/packages/backend/src/server/api/endpoints/roles/notes.ts
index 536384a381..4752561ad5 100644
--- a/packages/backend/src/server/api/endpoints/roles/notes.ts
+++ b/packages/backend/src/server/api/endpoints/roles/notes.ts
@@ -12,6 +12,7 @@ import { DI } from '@/di-symbols.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { IdService } from '@/core/IdService.js';
import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
+import ActiveUsersChart from '@/core/chart/charts/active-users.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -74,6 +75,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private noteEntityService: NoteEntityService,
private queryService: QueryService,
private fanoutTimelineService: FanoutTimelineService,
+ private readonly activeUsersChart: ActiveUsersChart,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
@@ -101,11 +103,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const query = this.notesRepository.createQueryBuilder('note')
.where('note.id IN (:...noteIds)', { noteIds: noteIds })
.andWhere('(note.visibility = \'public\')')
+ .orderBy('note.id', 'DESC')
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ .leftJoinAndSelect('reply.user', 'replyUser', 'replyUser.id = note.replyUserId')
+ .leftJoinAndSelect('renote.user', 'renoteUser', 'renoteUser.id = note.renoteUserId');
this.queryService.generateBlockedHostQueryForNote(query);
this.queryService.generateMutedUserQueryForNotes(query, me);
@@ -113,7 +116,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
const notes = await query.getMany();
- notes.sort((a, b) => a.id > b.id ? -1 : 1);
+
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
return await this.noteEntityService.packMany(notes, me);
});
diff --git a/packages/backend/src/server/api/stream/channel.ts b/packages/backend/src/server/api/stream/channel.ts
index 204ea9f705..3a82865577 100644
--- a/packages/backend/src/server/api/stream/channel.ts
+++ b/packages/backend/src/server/api/stream/channel.ts
@@ -61,6 +61,21 @@ export default abstract class Channel {
return this.connection.subscriber;
}
+ /**
+ * Checks if a note is visible to the current user *excluding* blocks and mutes.
+ */
+ protected isNoteVisibleToMe(note: Packed<'Note'>): boolean {
+ if (note.visibility === 'public') return true;
+ if (note.visibility === 'home') return true;
+ if (!this.user) return false;
+ if (this.user.id === note.userId) return true;
+ if (note.visibility === 'followers') {
+ return this.following[note.userId] != null;
+ }
+ if (!note.visibleUserIds) return false;
+ return note.visibleUserIds.includes(this.user.id);
+ }
+
/*
* ミュートとブロックされてるを処理する
*/
@@ -69,7 +84,7 @@ export default abstract class Channel {
if (note.user.requireSigninToViewContents && !this.user) return true;
// 流れてきたNoteがインスタンスミュートしたインスタンスが関わる
- if (isInstanceMuted(note, new Set<string>(this.userProfile?.mutedInstances ?? [])) && !this.following[note.userId]) return true;
+ if (isInstanceMuted(note, this.userMutedInstances) && !this.following[note.userId]) return true;
// 流れてきたNoteがミュートしているユーザーが関わる
if (isUserRelated(note, this.userIdsWhoMeMuting)) return true;
@@ -82,6 +97,15 @@ export default abstract class Channel {
// If it's a boost (pure renote) then we need to check the target as well
if (isPackedPureRenote(note) && note.renote && this.isNoteMutedOrBlocked(note.renote)) return true;
+ // Hide silenced notes
+ if (note.user.isSilenced || note.user.instance?.isSilenced) {
+ if (this.user == null) return true;
+ if (this.user.id === note.userId) return false;
+ if (this.following[note.userId] == null) return true;
+ }
+
+ // TODO muted threads
+
return false;
}
diff --git a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts
index 88cb9937b3..393fe3883c 100644
--- a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts
@@ -5,11 +5,9 @@
import { Injectable } from '@nestjs/common';
import type { Packed } from '@/misc/json-schema.js';
-import { MetaService } from '@/core/MetaService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import { RoleService } from '@/core/RoleService.js';
-import type { MiMeta } from '@/models/Meta.js';
import { isRenotePacked, isQuotePacked } from '@/misc/is-renote.js';
import type { JsonObject } from '@/misc/json-value.js';
import { UtilityService } from '@/core/UtilityService.js';
@@ -22,10 +20,8 @@ class BubbleTimelineChannel extends Channel {
private withRenotes: boolean;
private withFiles: boolean;
private withBots: boolean;
- private instance: MiMeta;
constructor(
- private metaService: MetaService,
private roleService: RoleService,
private readonly utilityService: UtilityService,
noteEntityService: NoteEntityService,
@@ -44,7 +40,6 @@ class BubbleTimelineChannel extends Channel {
this.withRenotes = !!(params.withRenotes ?? true);
this.withFiles = !!(params.withFiles ?? false);
this.withBots = !!(params.withBots ?? true);
- this.instance = await this.metaService.fetch();
// Subscribe events
this.subscriber.on('notesStream', this.onNote);
@@ -52,23 +47,36 @@ class BubbleTimelineChannel extends Channel {
@bindThis
private async onNote(note: Packed<'Note'>) {
+ const isMe = this.user?.id === note.userId;
+
if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
if (!this.withBots && note.user.isBot) return;
if (note.visibility !== 'public') return;
if (note.channelId != null) return;
- if (note.user.host == null) return;
if (!this.utilityService.isBubbledHost(note.user.host)) return;
- if (note.user.requireSigninToViewContents && this.user == null) return;
- if (isRenotePacked(note) && !isQuotePacked(note) && !this.withRenotes) return;
+ if (this.isNoteMutedOrBlocked(note)) return;
- if (note.user.isSilenced) {
- if (!this.user) return;
- if (note.userId !== this.user.id && !this.following[note.userId]) return;
+ if (note.reply) {
+ const reply = note.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ if (!this.following[note.userId]?.withReplies) {
+ // 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
+ if (reply.userId !== this.user?.id && !isMe && reply.userId !== note.userId) return;
+ }
}
- if (this.isNoteMutedOrBlocked(note)) return;
+ // 純粋なリノート(引用リノートでないリノート)の場合
+ if (isRenotePacked(note) && !isQuotePacked(note) && note.renote) {
+ if (!this.withRenotes) return;
+ if (note.renote.reply) {
+ const reply = note.renote.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信のリノートは弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ }
+ }
const clonedNote = await this.assignMyReaction(note);
await this.hideNote(clonedNote);
@@ -90,7 +98,6 @@ export class BubbleTimelineChannelService implements MiChannelService<false> {
public readonly kind = BubbleTimelineChannel.kind;
constructor(
- private metaService: MetaService,
private roleService: RoleService,
private noteEntityService: NoteEntityService,
private readonly utilityService: UtilityService,
@@ -100,7 +107,6 @@ export class BubbleTimelineChannelService implements MiChannelService<false> {
@bindThis
public create(id: string, connection: Channel['connection']): BubbleTimelineChannel {
return new BubbleTimelineChannel(
- this.metaService,
this.roleService,
this.utilityService,
this.noteEntityService,
diff --git a/packages/backend/src/server/api/stream/channels/global-timeline.ts b/packages/backend/src/server/api/stream/channels/global-timeline.ts
index c899ad9490..bac0277538 100644
--- a/packages/backend/src/server/api/stream/channels/global-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/global-timeline.ts
@@ -48,20 +48,36 @@ class GlobalTimelineChannel extends Channel {
@bindThis
private async onNote(note: Packed<'Note'>) {
+ const isMe = this.user?.id === note.userId;
+
if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
if (!this.withBots && note.user.isBot) return;
if (note.visibility !== 'public') return;
if (note.channelId != null) return;
- if (note.user.requireSigninToViewContents && this.user == null) return;
- if (note.renote && note.renote.user.requireSigninToViewContents && this.user == null) return;
- if (note.reply && note.reply.user.requireSigninToViewContents && this.user == null) return;
- if (isRenotePacked(note) && !isQuotePacked(note) && !this.withRenotes) return;
+ if (this.isNoteMutedOrBlocked(note)) return;
+ if (!this.isNoteVisibleToMe(note)) return;
- if (note.user.isSilenced && !this.following[note.userId] && note.userId !== this.user!.id) return;
+ if (note.reply) {
+ const reply = note.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ if (!this.following[note.userId]?.withReplies) {
+ // 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
+ if (reply.userId !== this.user?.id && !isMe && reply.userId !== note.userId) return;
+ }
+ }
- if (this.isNoteMutedOrBlocked(note)) return;
+ // 純粋なリノート(引用リノートでないリノート)の場合
+ if (isRenotePacked(note) && !isQuotePacked(note) && note.renote) {
+ if (!this.withRenotes) return;
+ if (note.renote.reply) {
+ const reply = note.renote.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信のリノートは弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ }
+ }
const clonedNote = await this.assignMyReaction(note);
await this.hideNote(clonedNote);
diff --git a/packages/backend/src/server/api/stream/channels/home-timeline.ts b/packages/backend/src/server/api/stream/channels/home-timeline.ts
index dfdb491113..d1dcbd07e5 100644
--- a/packages/backend/src/server/api/stream/channels/home-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/home-timeline.ts
@@ -50,37 +50,29 @@ class HomeTimelineChannel extends Channel {
if (!isMe && !Object.hasOwn(this.following, note.userId)) return;
}
- if (note.visibility === 'followers') {
- if (!isMe && !Object.hasOwn(this.following, note.userId)) return;
- } else if (note.visibility === 'specified') {
- if (!isMe && !note.visibleUserIds!.includes(this.user!.id)) return;
- }
+ if (this.isNoteMutedOrBlocked(note)) return;
+ if (!this.isNoteVisibleToMe(note)) return;
if (note.reply) {
const reply = note.reply;
- if (this.following[note.userId]?.withReplies) {
- // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
- if (reply.visibility === 'followers' && !Object.hasOwn(this.following, reply.userId) && reply.userId !== this.user!.id) return;
- } else {
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ if (!this.following[note.userId]?.withReplies) {
// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
if (reply.userId !== this.user!.id && !isMe && reply.userId !== note.userId) return;
}
}
- if (note.user.isSilenced && !this.following[note.userId] && note.userId !== this.user!.id) return;
-
// 純粋なリノート(引用リノートでないリノート)の場合
if (isRenotePacked(note) && !isQuotePacked(note) && note.renote) {
if (!this.withRenotes) return;
if (note.renote.reply) {
const reply = note.renote.reply;
// 自分のフォローしていないユーザーの visibility: followers な投稿への返信のリノートは弾く
- if (reply.visibility === 'followers' && !Object.hasOwn(this.following, reply.userId) && reply.userId !== this.user!.id) return;
+ if (!this.isNoteVisibleToMe(reply)) return;
}
}
- if (this.isNoteMutedOrBlocked(note)) return;
-
const clonedNote = await this.assignMyReaction(note);
await this.hideNote(clonedNote);
diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts
index 6cb425ff81..d923167e04 100644
--- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts
@@ -67,34 +67,26 @@ class HybridTimelineChannel extends Channel {
(note.channelId != null && this.followingChannels.has(note.channelId))
)) return;
- if (note.visibility === 'followers') {
- if (!isMe && !Object.hasOwn(this.following, note.userId)) return;
- } else if (note.visibility === 'specified') {
- if (!isMe && !note.visibleUserIds!.includes(this.user!.id)) return;
- }
-
if (this.isNoteMutedOrBlocked(note)) return;
+ if (!this.isNoteVisibleToMe(note)) return;
if (note.reply) {
const reply = note.reply;
- if ((this.following[note.userId]?.withReplies ?? false) || this.withReplies) {
- // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
- if (reply.visibility === 'followers' && !Object.hasOwn(this.following, reply.userId) && reply.userId !== this.user!.id) return;
- } else {
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ if (!this.following[note.userId]?.withReplies && !this.withReplies) {
// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
if (reply.userId !== this.user!.id && !isMe && reply.userId !== note.userId) return;
}
}
- if (note.user.isSilenced && !this.following[note.userId] && note.userId !== this.user!.id) return;
-
// 純粋なリノート(引用リノートでないリノート)の場合
if (isRenotePacked(note) && !isQuotePacked(note) && note.renote) {
if (!this.withRenotes) return;
if (note.renote.reply) {
const reply = note.renote.reply;
// 自分のフォローしていないユーザーの visibility: followers な投稿への返信のリノートは弾く
- if (reply.visibility === 'followers' && !Object.hasOwn(this.following, reply.userId) && reply.userId !== this.user!.id) return;
+ if (!this.isNoteVisibleToMe(reply)) return;
}
}
diff --git a/packages/backend/src/server/api/stream/channels/local-timeline.ts b/packages/backend/src/server/api/stream/channels/local-timeline.ts
index 82b128eae0..2eb3460efa 100644
--- a/packages/backend/src/server/api/stream/channels/local-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts
@@ -50,28 +50,37 @@ class LocalTimelineChannel extends Channel {
@bindThis
private async onNote(note: Packed<'Note'>) {
+ const isMe = this.user?.id === note.userId;
+
if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
if (!this.withBots && note.user.isBot) return;
if (note.user.host !== null) return;
if (note.visibility !== 'public') return;
if (note.channelId != null) return;
- if (note.user.requireSigninToViewContents && this.user == null) return;
- if (note.renote && note.renote.user.requireSigninToViewContents && this.user == null) return;
- if (note.reply && note.reply.user.requireSigninToViewContents && this.user == null) return;
+
+ if (this.isNoteMutedOrBlocked(note)) return;
+ if (!this.isNoteVisibleToMe(note)) return;
// 関係ない返信は除外
- if (note.reply && this.user && !this.following[note.userId]?.withReplies && !this.withReplies) {
+ if (note.reply) {
const reply = note.reply;
- // 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
- if (reply.userId !== this.user.id && note.userId !== this.user.id && reply.userId !== note.userId) return;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ if (!this.following[note.userId]?.withReplies) {
+ // 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
+ if (reply.userId !== this.user?.id && !isMe && reply.userId !== note.userId) return;
+ }
}
- if (note.user.isSilenced && !this.following[note.userId] && note.userId !== this.user!.id) return;
-
- if (isRenotePacked(note) && !isQuotePacked(note) && !this.withRenotes) return;
-
- if (this.isNoteMutedOrBlocked(note)) return;
+ if (isRenotePacked(note) && !isQuotePacked(note) && note.renote) {
+ if (!this.withRenotes) return;
+ if (note.renote.reply) {
+ const reply = note.renote.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信のリノートは弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ }
+ }
const clonedNote = await this.assignMyReaction(note);
await this.hideNote(clonedNote);
diff --git a/packages/backend/src/server/api/stream/channels/main.ts b/packages/backend/src/server/api/stream/channels/main.ts
index 6194bb78dd..193907504a 100644
--- a/packages/backend/src/server/api/stream/channels/main.ts
+++ b/packages/backend/src/server/api/stream/channels/main.ts
@@ -32,10 +32,12 @@ class MainChannel extends Channel {
switch (data.type) {
case 'notification': {
// Ignore notifications from instances the user has muted
- if (isUserFromMutedInstance(data.body, new Set<string>(this.userProfile?.mutedInstances ?? []))) return;
+ if (isUserFromMutedInstance(data.body, this.userMutedInstances)) return;
if (data.body.userId && this.userIdsWhoMeMuting.has(data.body.userId)) return;
if (data.body.note && data.body.note.isHidden) {
+ if (this.isNoteMutedOrBlocked(data.body.note)) return;
+ if (!this.isNoteVisibleToMe(data.body.id)) return;
const note = await this.noteEntityService.pack(data.body.note.id, this.user, {
detail: true,
});
@@ -44,9 +46,7 @@ class MainChannel extends Channel {
break;
}
case 'mention': {
- if (isInstanceMuted(data.body, new Set<string>(this.userProfile?.mutedInstances ?? []))) return;
-
- if (this.userIdsWhoMeMuting.has(data.body.userId)) return;
+ if (this.isNoteMutedOrBlocked(data.body)) return;
if (data.body.isHidden) {
const note = await this.noteEntityService.pack(data.body.id, this.user, {
detail: true,
diff --git a/packages/backend/src/server/api/stream/channels/role-timeline.ts b/packages/backend/src/server/api/stream/channels/role-timeline.ts
index 78cd9bf868..f5984b5ae9 100644
--- a/packages/backend/src/server/api/stream/channels/role-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/role-timeline.ts
@@ -9,6 +9,7 @@ import { bindThis } from '@/decorators.js';
import { RoleService } from '@/core/RoleService.js';
import type { GlobalEvents } from '@/core/GlobalEventService.js';
import type { JsonObject } from '@/misc/json-value.js';
+import { isQuotePacked, isRenotePacked } from '@/misc/is-renote.js';
import Channel, { type MiChannelService } from '../channel.js';
class RoleTimelineChannel extends Channel {
@@ -40,7 +41,9 @@ class RoleTimelineChannel extends Channel {
private async onEvent(data: GlobalEvents['roleTimeline']['payload']) {
if (data.type === 'note') {
const note = data.body;
+ const isMe = this.user?.id === note.userId;
+ // TODO this should be cached
if (!(await this.roleservice.isExplorable({ id: this.roleId }))) {
return;
}
@@ -48,6 +51,25 @@ class RoleTimelineChannel extends Channel {
if (this.isNoteMutedOrBlocked(note)) return;
+ if (note.reply) {
+ const reply = note.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ if (!this.following[note.userId]?.withReplies) {
+ // 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
+ if (reply.userId !== this.user?.id && !isMe && reply.userId !== note.userId) return;
+ }
+ }
+
+ // 純粋なリノート(引用リノートでないリノート)の場合
+ if (isRenotePacked(note) && !isQuotePacked(note) && note.renote) {
+ if (note.renote.reply) {
+ const reply = note.renote.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信のリノートは弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ }
+ }
+
const clonedNote = await this.assignMyReaction(note);
await this.hideNote(clonedNote);
diff --git a/packages/backend/src/server/api/stream/channels/user-list.ts b/packages/backend/src/server/api/stream/channels/user-list.ts
index 8a7c2b2633..3f1a5a8f8f 100644
--- a/packages/backend/src/server/api/stream/channels/user-list.ts
+++ b/packages/backend/src/server/api/stream/channels/user-list.ts
@@ -16,7 +16,8 @@ import Channel, { type MiChannelService } from '../channel.js';
class UserListChannel extends Channel {
public readonly chName = 'userList';
public static shouldShare = false;
- public static requireCredential = false as const;
+ public static requireCredential = true as const;
+ public static kind = 'read:account';
private listId: string;
private membershipsMap: Record<string, Pick<MiUserListMembership, 'withReplies'> | undefined> = {};
private listUsersClock: NodeJS.Timeout;
@@ -81,7 +82,7 @@ class UserListChannel extends Channel {
@bindThis
private async onNote(note: Packed<'Note'>) {
- const isMe = this.user!.id === note.userId;
+ const isMe = this.user?.id === note.userId;
// チャンネル投稿は無視する
if (note.channelId) return;
@@ -90,26 +91,28 @@ class UserListChannel extends Channel {
if (!Object.hasOwn(this.membershipsMap, note.userId)) return;
- if (note.visibility === 'followers') {
- if (!isMe && !Object.hasOwn(this.following, note.userId)) return;
- } else if (note.visibility === 'specified') {
- if (!note.visibleUserIds!.includes(this.user!.id)) return;
- }
+ if (this.isNoteMutedOrBlocked(note)) return;
+ if (!this.isNoteVisibleToMe(note)) return;
if (note.reply) {
const reply = note.reply;
- if (this.membershipsMap[note.userId]?.withReplies) {
- // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
- if (reply.visibility === 'followers' && !Object.hasOwn(this.following, reply.userId)) return;
- } else {
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ if (!this.following[note.userId]?.withReplies) {
// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
if (reply.userId !== this.user!.id && !isMe && reply.userId !== note.userId) return;
}
}
- if (isRenotePacked(note) && !isQuotePacked(note) && !this.withRenotes) return;
-
- if (this.isNoteMutedOrBlocked(note)) return;
+ // 純粋なリノート(引用リノートでないリノート)の場合
+ if (isRenotePacked(note) && !isQuotePacked(note) && note.renote) {
+ if (!this.withRenotes) return;
+ if (note.renote.reply) {
+ const reply = note.renote.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信のリノートは弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ }
+ }
const clonedNote = await this.assignMyReaction(note);
await this.hideNote(clonedNote);
@@ -128,7 +131,7 @@ class UserListChannel extends Channel {
}
@Injectable()
-export class UserListChannelService implements MiChannelService<false> {
+export class UserListChannelService implements MiChannelService<true> {
public readonly shouldShare = UserListChannel.shouldShare;
public readonly requireCredential = UserListChannel.requireCredential;
public readonly kind = UserListChannel.kind;