Skip to content

Commit

Permalink
enhance: チャンネルのフォロー/フォロー解除がHTLに即時反映されるように
Browse files Browse the repository at this point in the history
  • Loading branch information
hideki0403 committed Nov 23, 2023
1 parent d1a8d91 commit 78238fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
22 changes: 4 additions & 18 deletions packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { extractCustomEmojisFromMfm } from '@/misc/extract-custom-emojis-from-mf
import { extractHashtags } from '@/misc/extract-hashtags.js';
import type { IMentionedRemoteUsers } from '@/models/Note.js';
import { MiNote } from '@/models/Note.js';
import type { ChannelFollowingsRepository, ChannelsRepository, FollowingsRepository, InstancesRepository, MiFollowing, MutingsRepository, NotesRepository, NoteThreadMutingsRepository, UserListMembershipsRepository, UserProfilesRepository, UsersRepository } from '@/models/_.js';
import type { ChannelsRepository, FollowingsRepository, InstancesRepository, MiFollowing, MutingsRepository, NotesRepository, NoteThreadMutingsRepository, UserListMembershipsRepository, UserProfilesRepository, UsersRepository } from '@/models/_.js';
import type { MiDriveFile } from '@/models/DriveFile.js';
import type { MiApp } from '@/models/App.js';
import { concat } from '@/misc/prelude/array.js';
Expand Down Expand Up @@ -187,9 +187,6 @@ export class NoteCreateService implements OnApplicationShutdown {
@Inject(DI.followingsRepository)
private followingsRepository: FollowingsRepository,

@Inject(DI.channelFollowingsRepository)
private channelFollowingsRepository: ChannelFollowingsRepository,

private userEntityService: UserEntityService,
private noteEntityService: NoteEntityService,
private idService: IdService,
Expand Down Expand Up @@ -842,22 +839,11 @@ export class NoteCreateService implements OnApplicationShutdown {

if (note.channelId) {
this.funoutTimelineService.push(`channelTimeline:${note.channelId}`, note, this.config.perChannelMaxNoteCacheCount, r);
if (note.fileIds && note.fileIds.length > 0) {
this.funoutTimelineService.push(`channelTimelineWithFiles:${note.channelId}`, note, this.config.perChannelMaxNoteCacheCount / 2, r);
}

this.funoutTimelineService.push(`userTimelineWithChannel:${user.id}`, note, note.user.host == null ? meta.perLocalUserUserTimelineCacheMax : meta.perRemoteUserUserTimelineCacheMax, r);

const channelFollowings = await this.channelFollowingsRepository.find({
where: {
followeeId: note.channelId,
},
select: ['followerId'],
});

for (const channelFollowing of channelFollowings) {
this.funoutTimelineService.push(`homeTimeline:${channelFollowing.followerId}`, note, meta.perUserHomeTimelineCacheMax, r);
if (note.fileIds && note.fileIds.length > 0) {
this.funoutTimelineService.push(`homeTimelineWithFiles:${channelFollowing.followerId}`, note, meta.perUserHomeTimelineCacheMax / 2, r);
}
}
} else {
// TODO: キャッシュ?
// eslint-disable-next-line prefer-const
Expand Down
7 changes: 6 additions & 1 deletion packages/backend/src/server/api/endpoints/notes/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,22 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

const [
followings,
channelFollowings,
userIdsWhoMeMuting,
userIdsWhoMeMutingRenotes,
userIdsWhoBlockingMe,
] = await Promise.all([
this.cacheService.userFollowingsCache.fetch(me.id),
this.cacheService.userChannelFollowingsCache.fetch(me.id),
this.cacheService.userMutingsCache.fetch(me.id),
this.cacheService.renoteMutingsCache.fetch(me.id),
this.cacheService.userBlockedCache.fetch(me.id),
]);

let redisNotes = await this.funoutTimelineService.get(ps.withFiles ? `homeTimelineWithFiles:${me.id}` : `homeTimeline:${me.id}`, untilId, sinceId);
const timelines = ps.withFiles ? [`homeTimelineWithFiles:${me.id}`] : [`homeTimeline:${me.id}`];
channelFollowings.forEach(x => timelines.push(ps.withFiles ? `channelTimelineWithFiles:${x}` : `channelTimeline:${x}`));

let redisNotes = await this.funoutTimelineService.getMulti(timelines, untilId, sinceId);

redisNotes = redisNotes.filter(note => {
if (note.userId === me.id) return true;
Expand Down

0 comments on commit 78238fd

Please sign in to comment.