Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/api/internal/shared-sync/[board_name]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function GET(request: Request, { params }: { params: BoardRoutePara
}
console.log(`Passed auth for ${board_name}`);

const result = syncSharedData(board_name);
const result = await syncSharedData(board_name);

return NextResponse.json({
success: true,
Expand Down
11 changes: 6 additions & 5 deletions app/lib/data-sync/aurora/shared-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,25 +296,25 @@ async function updateSharedSyncs(
}
}

export async function getLastSharedSyncTimes(boardName: BoardName, tableNames = SHARED_SYNC_TABLES) {
export async function getLastSharedSyncTimes(boardName: BoardName) {
const sharedSyncsSchema = getTable('sharedSyncs', boardName);

const result = await db
.select({
table_name: sharedSyncsSchema.tableName,
last_synchronized_at: sharedSyncsSchema.lastSynchronizedAt,
})
.from(sharedSyncsSchema)
.where(inArray(sharedSyncsSchema.tableName, tableNames as unknown as Array<string>));
.from(sharedSyncsSchema);

return result;
}

export async function syncSharedData(
board: BoardName,
): Promise<Record<string, { synced: number }>> {
const allSyncTimes = await getLastSharedSyncTimes(board, SHARED_SYNC_TABLES);

console.log('Entered sync shared data');
const allSyncTimes = await getLastSharedSyncTimes(board);
console.log('Fetched previous sync times');
const syncParams: SyncOptions = {
tables: [...SHARED_SYNC_TABLES],
sharedSyncs: allSyncTimes.map((syncTime) => ({
Expand All @@ -326,6 +326,7 @@ export async function syncSharedData(
const syncResults = await sharedSync(board, syncParams);

console.log(`Received ${syncResults.PUT.climbs.length} climbs and ${syncResults.PUT.climb_stats.length} climb_stats`);

return upsertAllSharedTableData(board, syncResults);
}

Expand Down