mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: performance: userCache&scoreboard.pagination
This commit is contained in:
1 parent
0454acdbf9
commit
0d7c53b927
12 files changed
+244
-166
No files matched your search
@@ -1,9 +1,9 @@
|
||||
import { Cursor } from 'mongodb';
|
||||
import { ValidationError } from '../error';
|
||||
|
||||
async function paginate(
|
||||
cursor: Cursor, page: number, pageSize: number,
|
||||
): Promise<[any[]/* docs */, number/* numPages */, number/* count */]> {
|
||||
async function paginate<T>(
|
||||
cursor: Cursor<T>, page: number, pageSize: number,
|
||||
): Promise<[docs: T[], numPages: number, count: number]> {
|
||||
if (page <= 0) throw new ValidationError('page');
|
||||
const [count, pageDocs] = await Promise.all([
|
||||
cursor.count(),
|
||||
|
||||
Reference in new issue
Block a user