perf(backend): use limit() instead of take()

This commit is contained in:
syuilo
2023-07-08 16:53:07 +09:00
parent b056e8f5eb
commit 081a14d6f3
71 changed files with 76 additions and 75 deletions

View File

@@ -48,7 +48,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
.andWhere('clip.isPublic = true');
const clips = await query
.take(ps.limit)
.limit(ps.limit)
.getMany();
return await this.clipEntityService.packMany(clips, me);

View File

@@ -112,7 +112,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
.innerJoinAndSelect('following.follower', 'follower');
const followings = await query
.take(ps.limit)
.limit(ps.limit)
.getMany();
return await this.followingEntityService.packMany(followings, me, { populateFollower: true });

View File

@@ -112,7 +112,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
.innerJoinAndSelect('following.followee', 'followee');
const followings = await query
.take(ps.limit)
.limit(ps.limit)
.getMany();
return await this.followingEntityService.packMany(followings, me, { populateFollowee: true });

View File

@@ -47,7 +47,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
.andWhere('post.userId = :userId', { userId: ps.userId });
const posts = await query
.take(ps.limit)
.limit(ps.limit)
.getMany();
return await this.galleryPostEntityService.packMany(posts, me);

View File

@@ -120,7 +120,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
//#endregion
const timeline = await query.take(ps.limit).getMany();
const timeline = await query.limit(ps.limit).getMany();
return await this.noteEntityService.packMany(timeline, me);
});

View File

@@ -48,7 +48,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
.andWhere('page.visibility = \'public\'');
const pages = await query
.take(ps.limit)
.limit(ps.limit)
.getMany();
return await this.pageEntityService.packMany(pages);

View File

@@ -73,7 +73,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
this.queryService.generateVisibilityQuery(query, me);
const reactions = await query
.take(ps.limit)
.limit(ps.limit)
.getMany();
return await Promise.all(reactions.map(reaction => this.noteReactionEntityService.pack(reaction, me, { withNote: true })));

View File

@@ -70,7 +70,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
query.setParameters(followingQuery.getParameters());
const users = await query.take(ps.limit).skip(ps.offset).getMany();
const users = await query.limit(ps.limit).skip(ps.offset).getMany();
return await this.userEntityService.packMany(users, me, { detail: true });
});

View File

@@ -97,7 +97,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
users = await query
.orderBy('user.usernameLower', 'ASC')
.take(ps.limit)
.limit(ps.limit)
.getMany();
if (users.length < ps.limit) {
@@ -110,7 +110,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
const otherUsers = await otherQuery
.orderBy('user.updatedAt', 'DESC')
.take(ps.limit - users.length)
.limit(ps.limit - users.length)
.getMany();
users = users.concat(otherUsers);
@@ -122,7 +122,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
users = await query
.orderBy('user.updatedAt', 'DESC')
.take(ps.limit - users.length)
.limit(ps.limit - users.length)
.getMany();
}

View File

@@ -73,7 +73,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
users = await usernameQuery
.orderBy('user.updatedAt', 'DESC', 'NULLS LAST')
.take(ps.limit)
.limit(ps.limit)
.skip(ps.offset)
.getMany();
} else {
@@ -100,7 +100,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
users = await nameQuery
.orderBy('user.updatedAt', 'DESC', 'NULLS LAST')
.take(ps.limit)
.limit(ps.limit)
.skip(ps.offset)
.getMany();
@@ -126,7 +126,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
users = users.concat(await query
.orderBy('user.updatedAt', 'DESC', 'NULLS LAST')
.take(ps.limit)
.limit(ps.limit)
.skip(ps.offset)
.getMany(),
);