mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 07:24:13 +00:00 
			
		
		
		
	enhance: 各ノートが被クリップ数を保持するようにし、無意味にnotes/clipsを叩かないように
This commit is contained in:
		
							parent
							
								
									907d519da3
								
							
						
					
					
						commit
						f7c6932a83
					
				
					 9 changed files with 48 additions and 7 deletions
				
			
		| 
						 | 
					@ -1,3 +1,8 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * SPDX-FileCopyrightText: syuilo and other misskey contributors
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: AGPL-3.0-only
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class ServerIconsAndManifest1694850832075 {
 | 
					export class ServerIconsAndManifest1694850832075 {
 | 
				
			||||||
    name = 'ServerIconsAndManifest1694850832075'
 | 
					    name = 'ServerIconsAndManifest1694850832075'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										16
									
								
								packages/backend/migration/1694915420864-clipped-count.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								packages/backend/migration/1694915420864-clipped-count.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,16 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * SPDX-FileCopyrightText: syuilo and other misskey contributors
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: AGPL-3.0-only
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export class ClippedCount1694915420864 {
 | 
				
			||||||
 | 
					    name = 'ClippedCount1694915420864'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async up(queryRunner) {
 | 
				
			||||||
 | 
					        await queryRunner.query(`ALTER TABLE "note" ADD "clippedCount" smallint NOT NULL DEFAULT '0'`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async down(queryRunner) {
 | 
				
			||||||
 | 
					        await queryRunner.query(`ALTER TABLE "note" DROP COLUMN "clippedCount"`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -340,6 +340,8 @@ export class NoteEntityService implements OnModuleInit {
 | 
				
			||||||
			url: note.url ?? undefined,
 | 
								url: note.url ?? undefined,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			...(opts.detail ? {
 | 
								...(opts.detail ? {
 | 
				
			||||||
 | 
									clippedCount: note.clippedCount,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				reply: note.replyId ? this.pack(note.reply ?? note.replyId, me, {
 | 
									reply: note.replyId ? this.pack(note.reply ?? note.replyId, me, {
 | 
				
			||||||
					detail: false,
 | 
										detail: false,
 | 
				
			||||||
					_hint_: options?._hint_,
 | 
										_hint_: options?._hint_,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -107,6 +107,11 @@ export class MiNote {
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	public repliesCount: number;
 | 
						public repliesCount: number;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Column('smallint', {
 | 
				
			||||||
 | 
							default: 0,
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						public clippedCount: number;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Column('jsonb', {
 | 
						@Column('jsonb', {
 | 
				
			||||||
		default: {},
 | 
							default: {},
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,7 +8,7 @@ import ms from 'ms';
 | 
				
			||||||
import { Endpoint } from '@/server/api/endpoint-base.js';
 | 
					import { Endpoint } from '@/server/api/endpoint-base.js';
 | 
				
			||||||
import { IdService } from '@/core/IdService.js';
 | 
					import { IdService } from '@/core/IdService.js';
 | 
				
			||||||
import { DI } from '@/di-symbols.js';
 | 
					import { DI } from '@/di-symbols.js';
 | 
				
			||||||
import type { ClipNotesRepository, ClipsRepository } from '@/models/_.js';
 | 
					import type { ClipNotesRepository, ClipsRepository, NotesRepository } from '@/models/_.js';
 | 
				
			||||||
import { GetterService } from '@/server/api/GetterService.js';
 | 
					import { GetterService } from '@/server/api/GetterService.js';
 | 
				
			||||||
import { RoleService } from '@/core/RoleService.js';
 | 
					import { RoleService } from '@/core/RoleService.js';
 | 
				
			||||||
import { ApiError } from '../../error.js';
 | 
					import { ApiError } from '../../error.js';
 | 
				
			||||||
| 
						 | 
					@ -72,6 +72,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
 | 
				
			||||||
		@Inject(DI.clipNotesRepository)
 | 
							@Inject(DI.clipNotesRepository)
 | 
				
			||||||
		private clipNotesRepository: ClipNotesRepository,
 | 
							private clipNotesRepository: ClipNotesRepository,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							@Inject(DI.notesRepository)
 | 
				
			||||||
 | 
							private notesRepository: NotesRepository,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		private idService: IdService,
 | 
							private idService: IdService,
 | 
				
			||||||
		private roleService: RoleService,
 | 
							private roleService: RoleService,
 | 
				
			||||||
		private getterService: GetterService,
 | 
							private getterService: GetterService,
 | 
				
			||||||
| 
						 | 
					@ -115,9 +118,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
 | 
				
			||||||
				clipId: clip.id,
 | 
									clipId: clip.id,
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			await this.clipsRepository.update(clip.id, {
 | 
								this.clipsRepository.update(clip.id, {
 | 
				
			||||||
				lastClippedAt: new Date(),
 | 
									lastClippedAt: new Date(),
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								this.notesRepository.increment({ id: note.id }, 'clippedCount', 1);
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -52,6 +52,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
 | 
				
			||||||
		@Inject(DI.clipNotesRepository)
 | 
							@Inject(DI.clipNotesRepository)
 | 
				
			||||||
		private clipNotesRepository: ClipNotesRepository,
 | 
							private clipNotesRepository: ClipNotesRepository,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							@Inject(DI.notesRepository)
 | 
				
			||||||
 | 
							private notesRepository: NotesRepository,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		private getterService: GetterService,
 | 
							private getterService: GetterService,
 | 
				
			||||||
	) {
 | 
						) {
 | 
				
			||||||
		super(meta, paramDef, async (ps, me) => {
 | 
							super(meta, paramDef, async (ps, me) => {
 | 
				
			||||||
| 
						 | 
					@ -73,6 +76,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
 | 
				
			||||||
				noteId: note.id,
 | 
									noteId: note.id,
 | 
				
			||||||
				clipId: clip.id,
 | 
									clipId: clip.id,
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								this.notesRepository.decrement({ id: note.id }, 'clippedCount', 1);
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -94,13 +94,14 @@ function fetchNote() {
 | 
				
			||||||
		noteId: props.noteId,
 | 
							noteId: props.noteId,
 | 
				
			||||||
	}).then(res => {
 | 
						}).then(res => {
 | 
				
			||||||
		note = res;
 | 
							note = res;
 | 
				
			||||||
		Promise.all([
 | 
							// 古いノートは被クリップ数をカウントしていないので、2023-10-01以前のものは強制的にnotes/clipsを叩く
 | 
				
			||||||
 | 
							if (note.clippedCount > 0 || new Date(note.createdAt).getTime() < new Date('2023-10-01').getTime()) {
 | 
				
			||||||
			os.api('notes/clips', {
 | 
								os.api('notes/clips', {
 | 
				
			||||||
				noteId: note.id,
 | 
									noteId: note.id,
 | 
				
			||||||
			}),
 | 
								}).then((_clips) => {
 | 
				
			||||||
		]).then(([_clips]) => {
 | 
									clips = _clips;
 | 
				
			||||||
			clips = _clips;
 | 
								});
 | 
				
			||||||
		});
 | 
							}
 | 
				
			||||||
	}).catch(err => {
 | 
						}).catch(err => {
 | 
				
			||||||
		error = err;
 | 
							error = err;
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2539,6 +2539,7 @@ type Note = {
 | 
				
			||||||
    reactions: Record<string, number>;
 | 
					    reactions: Record<string, number>;
 | 
				
			||||||
    renoteCount: number;
 | 
					    renoteCount: number;
 | 
				
			||||||
    repliesCount: number;
 | 
					    repliesCount: number;
 | 
				
			||||||
 | 
					    clippedCount?: number;
 | 
				
			||||||
    poll?: {
 | 
					    poll?: {
 | 
				
			||||||
        expiresAt: DateString | null;
 | 
					        expiresAt: DateString | null;
 | 
				
			||||||
        multiple: boolean;
 | 
					        multiple: boolean;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -175,6 +175,7 @@ export type Note = {
 | 
				
			||||||
	reactions: Record<string, number>;
 | 
						reactions: Record<string, number>;
 | 
				
			||||||
	renoteCount: number;
 | 
						renoteCount: number;
 | 
				
			||||||
	repliesCount: number;
 | 
						repliesCount: number;
 | 
				
			||||||
 | 
						clippedCount?: number;
 | 
				
			||||||
	poll?: {
 | 
						poll?: {
 | 
				
			||||||
		expiresAt: DateString | null;
 | 
							expiresAt: DateString | null;
 | 
				
			||||||
		multiple: boolean;
 | 
							multiple: boolean;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue