mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
add index for sorting by saved_at
This commit is contained in:
parent
ff83147c09
commit
d9d800cfc4
3 changed files with 21 additions and 2 deletions
|
|
@ -93,6 +93,7 @@ export enum SortOrder {
|
|||
export interface Sort {
|
||||
by: string
|
||||
order?: SortOrder
|
||||
nulls?: 'NULLS FIRST' | 'NULLS LAST'
|
||||
}
|
||||
|
||||
interface Select {
|
||||
|
|
@ -332,8 +333,10 @@ export const buildQuery = (
|
|||
|
||||
const order =
|
||||
sortOrder === 'asc' ? SortOrder.ASCENDING : SortOrder.DESCENDING
|
||||
const nulls =
|
||||
order === SortOrder.ASCENDING ? 'NULLS FIRST' : 'NULLS LAST'
|
||||
|
||||
orders.push({ by: `library_item.${column}`, order })
|
||||
orders.push({ by: `library_item.${column}`, order, nulls })
|
||||
return null
|
||||
}
|
||||
case 'has':
|
||||
|
|
@ -613,12 +616,13 @@ export const searchLibraryItems = async (
|
|||
orders.push({
|
||||
by: 'library_item.saved_at',
|
||||
order: SortOrder.DESCENDING,
|
||||
nulls: 'NULLS LAST',
|
||||
})
|
||||
}
|
||||
|
||||
// add order by
|
||||
orders.forEach((order) => {
|
||||
queryBuilder.addOrderBy(order.by, order.order, 'NULLS LAST')
|
||||
queryBuilder.addOrderBy(order.by, order.order, order.nulls)
|
||||
})
|
||||
|
||||
const libraryItems = await queryBuilder.skip(from).take(size).getMany()
|
||||
|
|
|
|||
6
packages/db/migrations/0153.do.library_item_user_id_saved_at_idx.sql
Executable file
6
packages/db/migrations/0153.do.library_item_user_id_saved_at_idx.sql
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
-- Type: DO
|
||||
-- Name: library_item_user_id_saved_at_idx
|
||||
-- Description: Add library_item_user_id_saved_at_idx index on library_item table for user_id and saved_at
|
||||
|
||||
-- create index for sorting concurrently to avoid locking
|
||||
CREATE INDEX CONCURRENTLY IF NOT EXISTS library_item_user_id_saved_at_idx ON omnivore.library_item (user_id, saved_at DESC NULLS LAST);
|
||||
9
packages/db/migrations/0153.undo.library_item_user_id_saved_at_idx.sql
Executable file
9
packages/db/migrations/0153.undo.library_item_user_id_saved_at_idx.sql
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
-- Type: UNDO
|
||||
-- Name: library_item_user_id_saved_at_idx
|
||||
-- Description: Add library_item_user_id_saved_at_idx index on library_item table for user_id and saved_at
|
||||
|
||||
BEGIN;
|
||||
|
||||
DROP INDEX IF EXISTS omnivore.library_item_user_id_saved_at_idx;
|
||||
|
||||
COMMIT;
|
||||
Loading…
Reference in a new issue