use skip and take instead of limit, offset

This commit is contained in:
Hongbo Wu
2023-09-19 17:12:13 +08:00
parent 41e8ee3aca
commit 7225d861f3
4 changed files with 10 additions and 12 deletions

View File

@ -31,7 +31,7 @@ export const userRepository = entityManager.getRepository(User).extend({
.where({
profile: { username: In(TOP_USERS) },
})
.limit(MAX_RECORDS_LIMIT)
.take(MAX_RECORDS_LIMIT)
.getMany()
},
})

View File

@ -690,7 +690,7 @@ export const searchResolver = authorized<
pageInfo: {
hasPreviousPage: false,
startCursor,
hasNextPage: hasNextPage,
hasNextPage,
endCursor,
totalCount: count,
},

View File

@ -289,15 +289,14 @@ export const searchLibraryItems = async (
.leftJoinAndSelect('library_item.highlights', 'highlights')
.leftJoinAndSelect('highlights.user', 'user')
.leftJoinAndSelect('user.profile', 'profile')
.where('library_item.user_id = :userId', { userId })
// build the where clause
buildWhereClause(queryBuilder, args)
const libraryItems = await queryBuilder
.addOrderBy(`library_item.${sortField}`, sortOrder)
.offset(from)
.limit(size)
.skip(from)
.take(size)
.getMany()
const count = await queryBuilder.getCount()
@ -432,7 +431,7 @@ export const findLibraryItemsByPrefix = async (
.orWhere('library_item.site_name ILIKE :prefix', {
prefix: prefixWildcard,
})
.orderBy('library_item.saved_at', 'DESC')
.orderBy('library_item.savedAt', 'DESC')
.limit(limit)
.getMany()
)

View File

@ -67,12 +67,11 @@ export interface DateFilter {
}
export enum SortBy {
SAVED = 'saved_at',
UPDATED = 'updated_at',
PUBLISHED = 'published_at',
READ = 'read_at',
LISTENED = 'listened_at',
WORDS_COUNT = 'word_count',
SAVED = 'savedAt',
UPDATED = 'updatedAt',
PUBLISHED = 'publishedAt',
READ = 'readAt',
WORDS_COUNT = 'wordCount',
}
export enum SortOrder {