From 0def8fb048fb30b85015e6a7bc378dc3fdf51a12 Mon Sep 17 00:00:00 2001 From: Jamie Pine <32987599+jamiepine@users.noreply.github.com> Date: Sat, 26 Aug 2023 14:19:01 -0700 Subject: [PATCH] =?UTF-8?q?Revert=20"[ENG-1004]=20Add=20offset=20paginatio?= =?UTF-8?q?n=20capability=20to=20search=20queries=E2=80=A6=20(#1254)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revert "[ENG-1004] Add offset pagination capability to search queries (#1251)" This reverts commit a5a25b1439762b0f810a99364f7adb3af8149075. --- core/src/api/search.rs | 42 +++++------------------ interface/app/$libraryId/location/$id.tsx | 6 +--- interface/app/$libraryId/overview/data.ts | 15 +++----- packages/client/src/core.ts | 8 ++--- 4 files changed, 15 insertions(+), 56 deletions(-) diff --git a/core/src/api/search.rs b/core/src/api/search.rs index d59d6baff..6a91e23b6 100644 --- a/core/src/api/search.rs +++ b/core/src/api/search.rs @@ -357,13 +357,6 @@ pub fn mount() -> AlphaRouter { ) }) .procedure("paths", { - #[derive(Deserialize, Type, Debug)] - #[serde(rename_all = "camelCase")] - enum FilePathPagination { - Cursor { pub_id: file_path::pub_id::Type }, - Offset(i32), - } - #[derive(Deserialize, Type, Debug)] #[serde(rename_all = "camelCase")] struct FilePathSearchArgs { @@ -372,7 +365,7 @@ pub fn mount() -> AlphaRouter { #[specta(optional)] order: Option, #[specta(optional)] - pagination: Option, + cursor: Option>, #[serde(default)] filter: FilePathFilterArgs, #[serde(default = "default_group_directories")] @@ -388,7 +381,7 @@ pub fn mount() -> AlphaRouter { FilePathSearchArgs { take, order, - pagination, + cursor, filter, group_directories, }| async move { @@ -411,13 +404,8 @@ pub fn mount() -> AlphaRouter { query = query.order_by(order.into_param()); } - if let Some(pagination) = pagination { - match pagination { - FilePathPagination::Cursor { pub_id } => { - query = query.cursor(file_path::pub_id::equals(pub_id)); - } - FilePathPagination::Offset(offset) => query = query.skip(offset as i64), - } + if let Some(cursor) = cursor { + query = query.cursor(file_path::pub_id::equals(cursor)); } let (file_paths, cursor) = { @@ -478,13 +466,6 @@ pub fn mount() -> AlphaRouter { }) }) .procedure("objects", { - #[derive(Deserialize, Type, Debug)] - #[serde(rename_all = "camelCase")] - enum ObjectPagination { - Cursor { pub_id: object::pub_id::Type }, - Offset(i32), - } - #[derive(Deserialize, Type, Debug)] #[serde(rename_all = "camelCase")] struct ObjectSearchArgs { @@ -493,7 +474,7 @@ pub fn mount() -> AlphaRouter { #[specta(optional)] order: Option, #[specta(optional)] - pagination: Option, + cursor: Option>, #[serde(default)] filter: ObjectFilterArgs, } @@ -503,7 +484,7 @@ pub fn mount() -> AlphaRouter { ObjectSearchArgs { take, order, - pagination, + cursor, filter, }| async move { let Library { db, .. } = library.as_ref(); @@ -519,15 +500,8 @@ pub fn mount() -> AlphaRouter { query = query.order_by(order.into_param()); } - if let Some(pagination) = pagination { - match pagination { - ObjectPagination::Cursor { pub_id } => { - query = query.cursor(object::pub_id::equals(pub_id)); - } - ObjectPagination::Offset(offset) => { - query = query.skip(offset as i64); - } - } + if let Some(cursor) = cursor { + query = query.cursor(object::pub_id::equals(cursor)); } let (objects, cursor) = { diff --git a/interface/app/$libraryId/location/$id.tsx b/interface/app/$libraryId/location/$id.tsx index bfee6ef34..3516bfbcb 100644 --- a/interface/app/$libraryId/location/$id.tsx +++ b/interface/app/$libraryId/location/$id.tsx @@ -178,11 +178,7 @@ const useItems = ({ 'search.paths', { ...queryKey[1].arg, - pagination: { - cursor: { - pub_id: cursor - } - } + cursor } ]), getNextPageParam: (lastPage) => lastPage.cursor ?? undefined, diff --git a/interface/app/$libraryId/overview/data.ts b/interface/app/$libraryId/overview/data.ts index 9be786e37..fe5df5f48 100644 --- a/interface/app/$libraryId/overview/data.ts +++ b/interface/app/$libraryId/overview/data.ts @@ -7,7 +7,8 @@ import { useLibraryContext, useRspcLibraryContext } from '@sd/client'; -import { getExplorerStore } from '../Explorer/store'; +import { useExplorerContext } from '../Explorer/Context'; +import { getExplorerStore, useExplorerStore } from '../Explorer/store'; import { UseExplorerSettings } from '../Explorer/useExplorer'; export const IconForCategory: Partial> = { @@ -86,11 +87,7 @@ export function useItems( 'search.paths', { ...queryKey[1].arg, - pagination: { - cursor: { - pub_id: cursor - } - } + cursor } ]), getNextPageParam: (lastPage) => lastPage.cursor ?? undefined, @@ -119,11 +116,7 @@ export function useItems( 'search.objects', { ...queryKey[1].arg, - pagination: { - cursor: { - pub_id: cursor - } - } + cursor } ]), getNextPageParam: (lastPage) => lastPage.cursor ?? undefined diff --git a/packages/client/src/core.ts b/packages/client/src/core.ts index 1ea550660..b41eef871 100644 --- a/packages/client/src/core.ts +++ b/packages/client/src/core.ts @@ -142,9 +142,7 @@ export type FilePath = { id: number; pub_id: number[]; is_dir: boolean | null; c export type FilePathFilterArgs = { locationId?: number | null; search?: string | null; extension?: string | null; createdAt?: OptionalRange; path?: string | null; object?: ObjectFilterArgs | null } -export type FilePathPagination = { cursor: { pub_id: number[] } } | { offset: number } - -export type FilePathSearchArgs = { take?: number | null; order?: FilePathSearchOrdering | null; pagination?: FilePathPagination | null; filter?: FilePathFilterArgs; groupDirectories?: boolean } +export type FilePathSearchArgs = { take?: number | null; order?: FilePathSearchOrdering | null; cursor?: number[] | null; filter?: FilePathFilterArgs; groupDirectories?: boolean } export type FilePathSearchOrdering = { field: "name"; value: SortOrder } | { field: "sizeInBytes"; value: SortOrder } | { field: "dateCreated"; value: SortOrder } | { field: "dateModified"; value: SortOrder } | { field: "dateIndexed"; value: SortOrder } | { field: "object"; value: ObjectSearchOrdering } @@ -264,9 +262,7 @@ export type ObjectFilterArgs = { favorite?: boolean | null; hidden?: ObjectHidde export type ObjectHiddenFilter = "exclude" | "include" -export type ObjectPagination = { cursor: { pub_id: number[] } } | { offset: number } - -export type ObjectSearchArgs = { take?: number | null; order?: ObjectSearchOrdering | null; pagination?: ObjectPagination | null; filter?: ObjectFilterArgs } +export type ObjectSearchArgs = { take?: number | null; order?: ObjectSearchOrdering | null; cursor?: number[] | null; filter?: ObjectFilterArgs } export type ObjectSearchOrdering = { field: "dateAccessed"; value: SortOrder } | { field: "kind"; value: SortOrder }