🐛 Fixing pagination for "Shared with me"/ES (#778)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types */
|
||||
import { SearchDocumentsOptions } from "src/services/documents/types";
|
||||
import { TdriveServiceProvider } from "../../framework";
|
||||
import { ListResult } from "../../framework/api/crud-service";
|
||||
import {
|
||||
@@ -62,6 +63,7 @@ export interface SearchServiceAPI extends TdriveServiceProvider {
|
||||
getRepository<Entity>(table: string, entityType: EntityTarget<Entity>): SearchRepository<Entity>;
|
||||
upsert(entities: any[]): Promise<void>;
|
||||
remove(entities: any[]): Promise<void>;
|
||||
handlePagination(options: SearchDocumentsOptions): void;
|
||||
type: SearchConfiguration["type"];
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import { DatabaseServiceAPI } from "../database/api";
|
||||
import SearchRepository from "./repository";
|
||||
import { Client as OpenClient } from "@opensearch-project/opensearch";
|
||||
import { Client as ESClient } from "@elastic/elasticsearch";
|
||||
import { SearchDocumentsOptions } from "src/services/documents/types";
|
||||
|
||||
@ServiceName("search")
|
||||
@Consumes(["database"])
|
||||
@@ -96,4 +97,30 @@ export default class Search extends TdriveService<SearchServiceAPI> {
|
||||
api(): SearchServiceAPI {
|
||||
return this;
|
||||
}
|
||||
|
||||
handlePagination(options: SearchDocumentsOptions): void {
|
||||
if (this.type === "mongodb") {
|
||||
// No custom pagination logic for MongoDB
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.type === "elasticsearch" || this.type === "opensearch") {
|
||||
if (options.nextPage?.page_token) {
|
||||
// Set the scroll ID as the page token
|
||||
options.pagination = {
|
||||
...options.pagination,
|
||||
page_token: options.nextPage.page_token,
|
||||
};
|
||||
} else {
|
||||
// Clear pagination if no nextPage token is provided
|
||||
options.pagination = {
|
||||
limitStr: options.pagination?.limitStr,
|
||||
};
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle unsupported platform types
|
||||
throw new Error(`Pagination handling is not implemented for platform type: ${this.type}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +133,9 @@ export class DocumentsService {
|
||||
options.sort = this.getSortFieldMapping(options.sort);
|
||||
}
|
||||
|
||||
// Handle pagination differently for non-MongoDB platforms
|
||||
globalResolver.platformServices.search.handlePagination(options);
|
||||
|
||||
const fileList: ListResult<DriveFile> = await this.search(options, context);
|
||||
const result = fileList.getEntities();
|
||||
|
||||
|
||||
@@ -57,12 +57,18 @@ export type SearchDocumentsOptions = {
|
||||
onlyDirectlyShared?: boolean;
|
||||
onlyUploadedNotByMe?: boolean;
|
||||
pagination?: Paginable;
|
||||
nextPage?: {
|
||||
page_token: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type BrowseDocumentsOptions = {
|
||||
filter?: SearchDocumentsBody;
|
||||
sort?: SortType;
|
||||
paginate?: Paginable;
|
||||
nextPage?: {
|
||||
page_token: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type SearchDocumentsBody = {
|
||||
|
||||
@@ -213,6 +213,7 @@ export class DocumentsController {
|
||||
onlyUploadedNotByMe: true,
|
||||
sort: request.body.sort,
|
||||
pagination: request.body.paginate,
|
||||
nextPage: request.body.nextPage,
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user