1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-13 00:10:37 +02:00

Slow down migration

This commit is contained in:
Laurent Cozic
2021-10-28 17:06:16 +01:00
parent 0a7fdac850
commit 2cbcfa5bc8

View File

@ -1,5 +1,6 @@
import { Knex } from 'knex'; import { Knex } from 'knex';
import { DbConnection } from '../db'; import { DbConnection } from '../db';
import { msleep } from '../utils/time';
export async function up(db: DbConnection): Promise<any> { export async function up(db: DbConnection): Promise<any> {
if (!(await db.schema.hasColumn('items', 'owner_id'))) { if (!(await db.schema.hasColumn('items', 'owner_id'))) {
@ -22,7 +23,7 @@ export async function up(db: DbConnection): Promise<any> {
user_id: string; user_id: string;
} }
const pageSize = 10000; const pageSize = 1000;
const itemCount = (await db('items') const itemCount = (await db('items')
.count('id', { as: 'total' }) .count('id', { as: 'total' })
@ -42,11 +43,15 @@ export async function up(db: DbConnection): Promise<any> {
console.info(`Processing items ${itemDone} / ${itemCount}`); console.info(`Processing items ${itemDone} / ${itemCount}`);
await db.transaction(async trx => {
for (const item of items) { for (const item of items) {
await db('items').update({ owner_id: item.user_id }).where('id', '=', item.id); await trx('items').update({ owner_id: item.user_id }).where('id', '=', item.id);
} }
});
itemDone += items.length; itemDone += items.length;
await msleep(10000);
} }
await db.schema.alterTable('items', (table: Knex.CreateTableBuilder) => { await db.schema.alterTable('items', (table: Knex.CreateTableBuilder) => {