Skip to content

Commit fc8a52c

Browse files
authored
fix admin_migrateToGroups (tldraw#7049)
testing this some more in production I noticed that it was not effectively clearing the cache data for users who aren't signed in and active. That's because if they aren't connected there's no cache so the reboot doesn't get called. this fixes that. ### Change type - [x] `other` <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Deletes the user's R2 snapshot before rebooting in `admin_migrateToGroups` to properly reset cache for offline users, and adds more detailed debug logs around migration and reboots. > > - **Sync Worker** > - **Migration flow** (`apps/dotcom/sync-worker/src/TLUserDurableObject.ts`): > - Delete user snapshot `USER_DO_SNAPSHOTS.delete(getUserDoSnapshotKey(...))` before cache reboot in `admin_migrateToGroups` to ensure fresh state. > - Add debug logs: start, result, and completion of migration. > - **Reboot logging** (`apps/dotcom/sync-worker/src/UserDataSyncer.ts`): > - Expand `reboot` debug message to include `hard` and `delay` flags. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 65e16b9. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 40241b3 commit fc8a52c

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

apps/dotcom/sync-worker/src/TLUserDurableObject.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,16 +565,21 @@ export class TLUserDurableObject extends DurableObject<Environment> {
565565
async admin_migrateToGroups(userId: string, inviteSecret: string | null = null) {
566566
this.userId ??= userId
567567

568+
this.log.debug('migrating to groups', userId, inviteSecret)
568569
// Call the Postgres migration function
569570
const result = await sql<{
570571
files_migrated: number
571572
pinned_files_migrated: number
572573
flag_added: boolean
573574
}>`SELECT * FROM migrate_user_to_groups(${userId}, ${inviteSecret})`.execute(this.db)
574575

575-
// Reboot the user's cache to pick up the new data structure
576+
this.log.debug('migration result', result.rows[0])
577+
578+
await this.env.USER_DO_SNAPSHOTS.delete(getUserDoSnapshotKey(this.env, userId))
576579
await this.cache?.reboot({ delay: false, source: 'admin', hard: true })
577580

581+
this.log.debug('migration complete, user rebooted')
582+
578583
return result.rows[0]
579584
}
580585

apps/dotcom/sync-worker/src/UserDataSyncer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export class UserDataSyncer {
262262
this.ctx.abort()
263263
return
264264
}
265-
this.log.debug('rebooting', source)
265+
this.log.debug('rebooting', source, 'hard:', hard, 'delay:', delay)
266266
this.logEvent({ type: 'reboot', id: this.userId })
267267
await this.queue.push(async () => {
268268
if (delay) {

0 commit comments

Comments
 (0)