From c39e8e75e4ba231732a6466f609a62b48dca7e13 Mon Sep 17 00:00:00 2001 From: Ankit Tiwari Date: Sat, 30 Mar 2024 00:26:37 +0530 Subject: [PATCH] fix: PR changes --- .../postgresql/queries/BulkImportQueries.java | 17 +++++++++++------ .../postgresql/queries/GeneralQueries.java | 3 ++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/supertokens/storage/postgresql/queries/BulkImportQueries.java b/src/main/java/io/supertokens/storage/postgresql/queries/BulkImportQueries.java index 5fde6b87..75b4f053 100644 --- a/src/main/java/io/supertokens/storage/postgresql/queries/BulkImportQueries.java +++ b/src/main/java/io/supertokens/storage/postgresql/queries/BulkImportQueries.java @@ -64,9 +64,14 @@ public static String getQueryToCreateStatusUpdatedAtIndex(Start start) { + Config.getConfig(start).getBulkImportUsersTable() + " (app_id, status, updated_at)"; } - public static String getQueryToCreateCreatedAtIndex(Start start) { - return "CREATE INDEX IF NOT EXISTS bulk_import_users_created_at_index ON " - + Config.getConfig(start).getBulkImportUsersTable() + " (app_id, created_at)"; + public static String getQueryToCreatePaginationIndex1(Start start) { + return "CREATE INDEX IF NOT EXISTS bulk_import_users_pagination_index1 ON " + + Config.getConfig(start).getBulkImportUsersTable() + " (app_id, status, created_at DESC, id DESC)"; + } + + public static String getQueryToCreatePaginationIndex2(Start start) { + return "CREATE INDEX IF NOT EXISTS bulk_import_users_pagination_index2 ON " + + Config.getConfig(start).getBulkImportUsersTable() + " (app_id, created_at DESC, id DESC)"; } public static void insertBulkImportUsers(Start start, AppIdentifier appIdentifier, List users) @@ -124,8 +129,8 @@ public static List getBulkImportUsersAndChangeStatusToProcessing Connection sqlCon = (Connection) con.getConnection(); try { String selectQuery = "SELECT * FROM " + Config.getConfig(start).getBulkImportUsersTable() - + " WHERE status = 'NEW' AND app_id = ? " - + " OR (status = 'PROCESSING' AND updated_at < EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000 - 60 * 1000) " + + " WHERE app_id = ?" + + " AND (status = 'NEW' OR (status = 'PROCESSING' AND updated_at < EXTRACT(EPOCH FROM CURRENT_TIMESTAMP) * 1000 - 60 * 1000))" + " LIMIT ? FOR UPDATE SKIP LOCKED"; List bulkImportUsers = new ArrayList<>(); @@ -180,7 +185,7 @@ public static List getBulkImportUsers(Start start, AppIdentifier if (bulkImportUserId != null && createdAt != null) { queryBuilder - .append(" AND created_at < ? OR (created_at = ? AND id <= ?)"); + .append(" AND (created_at < ? OR (created_at = ? AND id <= ?))"); parameters.add(createdAt); parameters.add(createdAt); parameters.add(bulkImportUserId); diff --git a/src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java b/src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java index 5e8574a2..2102d0e0 100644 --- a/src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java +++ b/src/main/java/io/supertokens/storage/postgresql/queries/GeneralQueries.java @@ -546,7 +546,8 @@ public static void createTablesIfNotExists(Start start) throws SQLException, Sto update(start, BulkImportQueries.getQueryToCreateBulkImportUsersTable(start), NO_OP_SETTER); // index: update(start, BulkImportQueries.getQueryToCreateStatusUpdatedAtIndex(start), NO_OP_SETTER); - update(start, BulkImportQueries.getQueryToCreateCreatedAtIndex(start), NO_OP_SETTER); + update(start, BulkImportQueries.getQueryToCreatePaginationIndex1(start), NO_OP_SETTER); + update(start, BulkImportQueries.getQueryToCreatePaginationIndex2(start), NO_OP_SETTER); } } catch (Exception e) {