1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-11 18:24:43 +02:00

Server: Fixed /items page when using Postgres

This commit is contained in:
Laurent Cozic 2021-05-15 15:10:40 +02:00
parent 2331d3487b
commit 2d0580ff71
3 changed files with 45 additions and 3 deletions

View File

@ -378,6 +378,7 @@ export default class ItemModel extends BaseModel<Item> {
public async childrenCount(userId: Uuid, pathQuery: string = ''): Promise<number> {
const query = this.childrenQuery(userId, pathQuery);
query.groupBy('items.id');
return query.count();
}

View File

@ -0,0 +1,44 @@
import { beforeAllDb, afterAllTests, beforeEachDb, createItemTree, createUserAndSession } from '../../utils/testing/testUtils';
import { execRequest } from '../../utils/testing/apiUtils';
describe('index_items', function() {
beforeAll(async () => {
await beforeAllDb('index_items');
});
afterAll(async () => {
await afterAllTests();
});
beforeEach(async () => {
await beforeEachDb();
});
test('should list the user items', async function() {
const { user: user1, session: session1 } = await createUserAndSession(1);
const items: any = {};
for (let i = 1; i <= 150; i++) {
items[(`${i}`).padStart(32, '0')] = {};
}
await createItemTree(user1.id, '', items);
// Just some basic tests to check that we're seeing at least the first
// and last item of each page.
{
const response: string = await execRequest(session1.id, 'GET', 'items');
expect(response.includes('00000000000000000000000000000001.md')).toBe(true);
expect(response.includes('00000000000000000000000000000100.md')).toBe(true);
}
{
const response: string = await execRequest(session1.id, 'GET', 'items', null, { query: { page: 2 } });
expect(response.includes('00000000000000000000000000000101.md')).toBe(true);
expect(response.includes('00000000000000000000000000000150.md')).toBe(true);
}
});
});

View File

@ -14,7 +14,6 @@ import { View } from '../../services/MustacheService';
function makeFilePagination(query: any): Pagination {
const limit = Number(query.limit) || pageMaxSize;
const order: PaginationOrder[] = requestPaginationOrder(query, 'name', PaginationOrderDir.ASC);
// order.splice(0, 0, { by: 'is_directory', dir: PaginationOrderDir.DESC });
const page: number = 'page' in query ? Number(query.page) : 1;
const output: Pagination = { limit, order, page };
@ -24,8 +23,6 @@ function makeFilePagination(query: any): Pagination {
const router = new Router();
// router.alias(HttpMethod.GET, 'items', 'items/:id');
router.get('items', async (_path: SubPath, ctx: AppContext) => {
// Query parameters that should be appended to pagination-related URLs
const baseUrlQuery = filterPaginationQueryParams(ctx.query);