diff --git a/packages/api/src/services/create_page_save_request.ts b/packages/api/src/services/create_page_save_request.ts index 084f7da3f..ce4ce137b 100644 --- a/packages/api/src/services/create_page_save_request.ts +++ b/packages/api/src/services/create_page_save_request.ts @@ -16,7 +16,7 @@ import { libraryItemToArticleSavingRequest, } from '../utils/helpers' import { logger } from '../utils/logger' -import { countByCreatedAt, createOrUpdateLibraryItem } from './library_item' +import { countBySavedAt, createOrUpdateLibraryItem } from './library_item' interface PageSaveRequest { user: User @@ -38,12 +38,12 @@ const SAVING_CONTENT = 'Your link is being saved...' const isPrivateIP = privateIpLib.default -// 5 articles added in the last minute: use low queue +// 5 items saved in the last minute: use low queue // default: use normal queue const getPriorityByRateLimit = async ( userId: string ): Promise<'low' | 'high'> => { - const count = await countByCreatedAt(userId, new Date(Date.now() - 60 * 1000)) + const count = await countBySavedAt(userId, new Date(Date.now() - 60 * 1000)) return count >= 5 ? 'low' : 'high' } diff --git a/packages/api/src/services/library_item.ts b/packages/api/src/services/library_item.ts index e2f73cc0e..cf0f080fb 100644 --- a/packages/api/src/services/library_item.ts +++ b/packages/api/src/services/library_item.ts @@ -1004,7 +1004,7 @@ export const findLibraryItemsByPrefix = async ( ) } -export const countByCreatedAt = async ( +export const countBySavedAt = async ( userId: string, startDate = new Date(0), endDate = new Date() @@ -1014,7 +1014,7 @@ export const countByCreatedAt = async ( tx .createQueryBuilder(LibraryItem, 'library_item') .where('library_item.user_id = :userId', { userId }) - .andWhere('library_item.created_at between :startDate and :endDate', { + .andWhere('library_item.saved_at between :startDate and :endDate', { startDate, endDate, }) diff --git a/packages/api/src/services/update_pdf_content.ts b/packages/api/src/services/update_pdf_content.ts index ed9822ce2..75d3e8438 100644 --- a/packages/api/src/services/update_pdf_content.ts +++ b/packages/api/src/services/update_pdf_content.ts @@ -40,8 +40,7 @@ export const updateContentForFileItem = async (msg: UpdateContentMessage) => { .withRepository(libraryItemRepository) .createQueryBuilder('item') .innerJoinAndSelect('item.uploadFile', 'file') - .where('item.user = :userId', { userId: uploadFile.user.id }) - .andWhere('file.id = :fileId', { fileId }) + .where('file.id = :fileId', { fileId }) .getOne(), undefined, uploadFile.user.id diff --git a/packages/db/migrations/0162.do.library_item_user_id_state_index.sql b/packages/db/migrations/0162.do.library_item_user_id_state_index.sql new file mode 100755 index 000000000..942896ca1 --- /dev/null +++ b/packages/db/migrations/0162.do.library_item_user_id_state_index.sql @@ -0,0 +1,5 @@ +-- Type: DO +-- Name: library_item_user_id_state_index +-- Description: Create an index on omnivore.library_item table for querying by user_id and state + +CREATE INDEX CONCURRENTLY IF NOT EXISTS library_item_user_id_state_idx ON omnivore.library_item (user_id, state); diff --git a/packages/db/migrations/0162.undo.library_item_user_id_state_index.sql b/packages/db/migrations/0162.undo.library_item_user_id_state_index.sql new file mode 100755 index 000000000..b3d612b9b --- /dev/null +++ b/packages/db/migrations/0162.undo.library_item_user_id_state_index.sql @@ -0,0 +1,9 @@ +-- Type: UNDO +-- Name: library_item_user_id_state_index +-- Description: Create an index on omnivore.library_item table for querying by user_id and state + +BEGIN; + +DROP INDEX IF EXISTS omnivore.library_item_user_id_state_idx; + +COMMIT; diff --git a/packages/db/migrations/0163.do.api_key_index.sql b/packages/db/migrations/0163.do.api_key_index.sql new file mode 100755 index 000000000..03db73c1d --- /dev/null +++ b/packages/db/migrations/0163.do.api_key_index.sql @@ -0,0 +1,5 @@ +-- Type: DO +-- Name: api_key_index +-- Description: Create an index for checking key in api_key table + +CREATE INDEX CONCURRENTLY IF NOT EXISTS api_key_key_idx ON omnivore.api_key (key); diff --git a/packages/db/migrations/0163.undo.api_key_index.sql b/packages/db/migrations/0163.undo.api_key_index.sql new file mode 100755 index 000000000..46dfa8cf6 --- /dev/null +++ b/packages/db/migrations/0163.undo.api_key_index.sql @@ -0,0 +1,9 @@ +-- Type: UNDO +-- Name: api_key_index +-- Description: Create an index for checking key in api_key table + +BEGIN; + +DROP INDEX IF EXISTS omnivore.api_key_key_idx; + +COMMIT; diff --git a/packages/db/migrations/0164.do.library_item_file_id_index.sql b/packages/db/migrations/0164.do.library_item_file_id_index.sql new file mode 100755 index 000000000..f962642dd --- /dev/null +++ b/packages/db/migrations/0164.do.library_item_file_id_index.sql @@ -0,0 +1,5 @@ +-- Type: DO +-- Name: library_item_file_id_index +-- Description: create an index for upload_file_id column on library_item table + +CREATE INDEX CONCURRENTLY IF NOT EXISTS library_item_upload_file_id_idx ON omnivore.library_item (upload_file_id); diff --git a/packages/db/migrations/0164.undo.library_item_file_id_index.sql b/packages/db/migrations/0164.undo.library_item_file_id_index.sql new file mode 100755 index 000000000..e2db369e7 --- /dev/null +++ b/packages/db/migrations/0164.undo.library_item_file_id_index.sql @@ -0,0 +1,9 @@ +-- Type: UNDO +-- Name: library_item_file_id_index +-- Description: create an index for upload_file_id column on library_item table + +BEGIN; + +DROP INDEX IF EXISTS omnivore.library_item_upload_file_id_idx; + +COMMIT;