Clear timeouts in tag queries migration

This commit is contained in:
Alex Gleason 2024-07-29 15:37:45 -05:00
parent 48a4e30e38
commit 31f5254fb3
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -11,12 +11,13 @@ export async function up(db: Kysely<any>): Promise<void> {
.addColumn('created_at', 'integer', (col) => col.notNull()) .addColumn('created_at', 'integer', (col) => col.notNull())
.execute(); .execute();
setTimeout(() => { let iid: number | undefined;
const tid = setTimeout(() => {
console.warn( console.warn(
'Recreating the tags table to boost performance. Depending on the size of your database, this could take a very long time, even as long as 2 days!', 'Recreating the tags table to boost performance. Depending on the size of your database, this could take a very long time, even as long as 2 days!',
); );
const emojis = ['⚡', '🐛', '🔎', '😂', '😅', '😬', '😭', '🙃', '🤔', '🧐', '🧐', '🫠']; const emojis = ['⚡', '🐛', '🔎', '😂', '😅', '😬', '😭', '🙃', '🤔', '🧐', '🧐', '🫠'];
setInterval(() => { iid = setInterval(() => {
const emoji = emojis[Math.floor(Math.random() * emojis.length)]; const emoji = emojis[Math.floor(Math.random() * emojis.length)];
console.info(`Recreating tags table... ${emoji}`); console.info(`Recreating tags table... ${emoji}`);
}, 60_000); }, 60_000);
@ -32,6 +33,9 @@ export async function up(db: Kysely<any>): Promise<void> {
nostr_tags as t LEFT JOIN nostr_events e on t.event_id = e.id; nostr_tags as t LEFT JOIN nostr_events e on t.event_id = e.id;
`.execute(db); `.execute(db);
clearTimeout(tid);
if (iid) clearInterval(iid);
// Drop the old table and rename it. // Drop the old table and rename it.
await db.schema.dropTable('nostr_tags').execute(); await db.schema.dropTable('nostr_tags').execute();
await db.schema.alterTable('nostr_tags_new').renameTo('nostr_tags').execute(); await db.schema.alterTable('nostr_tags_new').renameTo('nostr_tags').execute();