AppView in a box as a Vite plugin thing hatk.dev
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: admin resync uses runBackfill with post-backfill restart

- Resync endpoint sets repos to pending then calls runBackfill
instead of triggerAutoBackfill, using the same batch worker pool
- runBackfill returns record count; restart only if work was done
- Shared runBackfillAndRestart function used by both boot and resync

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+31 -23
+29 -22
packages/hatk/src/main.ts
··· 149 149 150 150 // 5. Start server immediately (don't wait for backfill) 151 151 const collectionSet = new Set(collections) 152 - startServer(config.port, collections, config.publicDir, config.oauth, config.admins) 152 + 153 + const backfillOpts = { 154 + pdsUrl: relayHttpUrl(config.relay), 155 + plcUrl: config.plc, 156 + collections: collectionSet, 157 + config: config.backfill, 158 + } 159 + 160 + function runBackfillAndRestart() { 161 + runBackfill(backfillOpts) 162 + .then((recordCount) => { 163 + log('[main] Backfill complete, rebuilding FTS indexes...') 164 + return rebuildAllIndexes(collections).then(() => recordCount) 165 + }) 166 + .then((recordCount) => { 167 + log('[main] FTS indexes ready') 168 + if (recordCount > 0) { 169 + logMemory('after-backfill') 170 + log('[main] Restarting to reclaim memory...') 171 + process.exit(1) 172 + } 173 + }) 174 + .catch((err) => { 175 + console.error('[main] Backfill error:', err.message) 176 + }) 177 + } 178 + 179 + startServer(config.port, collections, config.publicDir, config.oauth, config.admins, undefined, runBackfillAndRestart) 153 180 154 181 log(`\nhatk running:`) 155 182 log(` Relay: ${config.relay}`) ··· 179 206 }) 180 207 181 208 // 7. Run backfill in background 182 - runBackfill({ 183 - pdsUrl: relayHttpUrl(config.relay), 184 - plcUrl: config.plc, 185 - collections: collectionSet, 186 - config: config.backfill, 187 - }) 188 - .then((recordCount) => { 189 - log('[main] Backfill complete, rebuilding FTS indexes...') 190 - return rebuildAllIndexes(collections).then(() => recordCount) 191 - }) 192 - .then((recordCount) => { 193 - log('[main] FTS indexes ready') 194 - if (recordCount > 0) { 195 - logMemory('after-backfill') 196 - log('[main] Restarting to reclaim memory...') 197 - process.exit(1) 198 - } 199 - }) 200 - .catch((err) => { 201 - console.error('[main] Backfill error:', err.message) 202 - }) 209 + runBackfillAndRestart() 203 210 204 211 // Graceful shutdown 205 212 process.on('SIGTERM', () => {
+2 -1
packages/hatk/src/server.ts
··· 83 83 oauth: OAuthConfig | null, 84 84 admins: string[] = [], 85 85 resolveViewer?: (req: IncomingMessage) => { did: string } | null, 86 + onResync?: () => void, 86 87 ): Server { 87 88 const coreXrpc = (method: string) => `/xrpc/dev.hatk.${method}` 88 89 ··· 528 529 } 529 530 for (const did of repoList) { 530 531 await setRepoStatus(did, 'pending') 531 - triggerAutoBackfill(did) 532 532 } 533 533 jsonResponse(res, { resyncing: repoList.length }) 534 + if (onResync) onResync() 534 535 return 535 536 } 536 537