Skip to content

Commit

Permalink
fix: PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
anku255 committed Mar 29, 2024
1 parent 6d4da2e commit c39e8e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<BulkImportUser> users)
Expand Down Expand Up @@ -124,8 +129,8 @@ public static List<BulkImportUser> 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<BulkImportUser> bulkImportUsers = new ArrayList<>();
Expand Down Expand Up @@ -180,7 +185,7 @@ public static List<BulkImportUser> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c39e8e7

Please sign in to comment.