enhance(backend): remove totalItems from liked collection

This commit is contained in:
Daiki Mizukami 2024-08-14 18:12:45 +09:00
parent 69bf40341d
commit 2f2a0e3c5e
No known key found for this signature in database
GPG key ID: 10478E598B944AA2
3 changed files with 13 additions and 17 deletions

View file

@ -667,7 +667,7 @@ export class ApRendererService {
* @param orderedItems attached objects (optional) * @param orderedItems attached objects (optional)
*/ */
@bindThis @bindThis
public renderOrderedCollection(id: string, totalItems: number, first?: string, last?: string, orderedItems?: IObject[]) { public renderOrderedCollection(id: string, totalItems?: number, first?: string, last?: string, orderedItems?: IObject[]) {
const page: any = { const page: any = {
id, id,
type: 'OrderedCollection', type: 'OrderedCollection',

View file

@ -96,14 +96,14 @@ export interface IActivity extends IObject {
export interface ICollection extends IObject { export interface ICollection extends IObject {
type: 'Collection'; type: 'Collection';
totalItems: number; totalItems?: number;
first?: IObject | string; first?: IObject | string;
items?: ApObject; items?: ApObject;
} }
export interface IOrderedCollection extends IObject { export interface IOrderedCollection extends IObject {
type: 'OrderedCollection'; type: 'OrderedCollection';
totalItems: number; totalItems?: number;
first?: IObject | string; first?: IObject | string;
orderedItems?: ApObject; orderedItems?: ApObject;
} }

View file

@ -386,25 +386,22 @@ export class ActivityPubServerService {
const limit = 10; const limit = 10;
const partOf = `${this.config.url}/users/${userId}/liked`; const partOf = `${this.config.url}/users/${userId}/liked`;
const query = this.noteReactionsRepository.createQueryBuilder('reaction')
.andWhere('reaction.userId = :userId', { userId: user.id });
if (page) { if (page) {
const countPromise = query.getCount(); const query = this.noteReactionsRepository.createQueryBuilder('reaction')
.andWhere('reaction.userId = :userId', { userId: user.id });
// カーソルが指定されている場合 // カーソルが指定されている場合
if (cursor) { if (cursor) {
query.andWhere('reaction.id < :id', { id: cursor }); query.andWhere('reaction.id < :id', { id: cursor });
} }
const [reactions, reactionsCount] = await Promise.all([ const reactions = await query
query .limit(limit + 1)
.limit(limit + 1) .orderBy('reaction.id', 'DESC')
.orderBy('reaction.id', 'DESC') .innerJoinAndSelect('reaction.note', 'note')
.innerJoinAndSelect('reaction.note', 'note') .distinctOn(['note.id'])
.getMany(), .getMany();
countPromise,
]);
// 「次のページ」があるかどうか // 「次のページ」があるかどうか
const inStock = reactions.length === limit + 1; const inStock = reactions.length === limit + 1;
@ -416,7 +413,7 @@ export class ActivityPubServerService {
page: 'true', page: 'true',
cursor, cursor,
})}`, })}`,
reactionsCount, reactedNotes, partOf, undefined, reactedNotes, partOf,
undefined, undefined,
inStock ? `${partOf}?${url.query({ inStock ? `${partOf}?${url.query({
page: 'true', page: 'true',
@ -428,10 +425,9 @@ export class ActivityPubServerService {
return (this.apRendererService.addContext(rendered)); return (this.apRendererService.addContext(rendered));
} else { } else {
// index page // index page
const reactionsCount = await query.getCount();
const rendered = this.apRendererService.renderOrderedCollection( const rendered = this.apRendererService.renderOrderedCollection(
partOf, partOf,
reactionsCount, undefined,
`${partOf}?page=true`, `${partOf}?page=true`,
); );
reply.header('Cache-Control', 'public, max-age=180'); reply.header('Cache-Control', 'public, max-age=180');