assistant 不同时操作多张表,减少死锁概率
This commit is contained in:
@@ -13,6 +13,7 @@ function getDiffSet(a, b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function migrateIdsFromCheckToFetch(tableName, fieldName, insertSql = null) {
|
async function migrateIdsFromCheckToFetch(tableName, fieldName, insertSql = null) {
|
||||||
|
try {
|
||||||
// console.log(`更新待爬取列表: ${tableName}`);
|
// console.log(`更新待爬取列表: ${tableName}`);
|
||||||
|
|
||||||
let stepLength = 5000;
|
let stepLength = 5000;
|
||||||
@@ -41,34 +42,39 @@ async function migrateIdsFromCheckToFetch(tableName, fieldName, insertSql = null
|
|||||||
// console.log(result);
|
// console.log(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 从待检查表中删除
|
// 从待检查表中删除
|
||||||
if (ids.length > 0)
|
if (ids.length > 0)
|
||||||
await dbUtils.query(`DELETE FROM wait_check_${tableName} WHERE id IN ?`, [[ids]]);
|
await dbUtils.query(`DELETE FROM wait_check_${tableName} WHERE id IN ?`, [[ids]]);
|
||||||
console.log(`table: ${tableName}\t| ${fill(ids[0], 10)} - ${fill(ids.slice(-1)[0], 10)} ${fill(`(${finalIds.length}/${ids.length})`, 10, ' ', true)}\t| affected: ${result?.affectedRows}`);
|
console.log(`table: ${tableName}\t| ${fill(ids[0], 10)} - ${fill(ids.slice(-1)[0], 10)} ${fill(`(${finalIds.length}/${ids.length})`, 10, ' ', true)}\t| affected: ${result?.affectedRows}`);
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getPromise(tableName, fieldName, insertSql) {
|
async function getPromise(tableName, fieldName, insertSql) {
|
||||||
try {
|
|
||||||
return new Promise(async function (resolve) {
|
return new Promise(async function (resolve) {
|
||||||
await migrateIdsFromCheckToFetch(tableName, fieldName, insertSql);
|
await migrateIdsFromCheckToFetch(tableName, fieldName, insertSql);
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
await sleepUtils.sleep(10 * 1000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
async function updateWaitTable() {
|
async function updateWaitTable() {
|
||||||
console.log(`更新待爬取列表`);
|
console.log(`更新待爬取列表`);
|
||||||
await Promise.all([
|
|
||||||
getPromise("song", "song_id"),
|
// 不同时操作多张表,减少死锁概率
|
||||||
getPromise("lyric", "song_id"),
|
await migrateIdsFromCheckToFetch("song", "song_id");
|
||||||
getPromise("comment", "song_id", `INSERT IGNORE INTO comment_progress (song_id) VALUES ?`),
|
await migrateIdsFromCheckToFetch("lyric", "song_id");
|
||||||
getPromise("album", "album_id"),
|
await migrateIdsFromCheckToFetch("comment", "song_id", `INSERT IGNORE INTO comment_progress (song_id) VALUES ?`);
|
||||||
getPromise("artist", "artist_id")
|
await migrateIdsFromCheckToFetch("album", "album_id");
|
||||||
]);
|
await migrateIdsFromCheckToFetch("artist", "artist_id");
|
||||||
|
|
||||||
|
// await Promise.all([
|
||||||
|
// getPromise("song", "song_id"),
|
||||||
|
// getPromise("lyric", "song_id"),
|
||||||
|
// getPromise("comment", "song_id", `INSERT IGNORE INTO comment_progress (song_id) VALUES ?`),
|
||||||
|
// getPromise("album", "album_id"),
|
||||||
|
// getPromise("artist", "artist_id")
|
||||||
|
// ]);
|
||||||
console.log("All done.\n");
|
console.log("All done.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user