fix: 无限循环处理

pull/635/head
bigfengyu 5 years ago
parent 886b16f037
commit e70f54687d

@ -1,44 +1,50 @@
// 补数据 token
import nanoid = require("nanoid");
import sequelize from "../models/sequelize";
import { Repository } from "../models";
import nanoid = require("nanoid")
import sequelize from "../models/sequelize"
import { Repository } from "../models"
const chalk = require("chalk");
(async () => {
sequelize.model(Repository);
sequelize.model(Repository)
const cnt = await Repository.count({
where: {
// tslint:disable-next-line: no-null-keyword
token: null
}
});
})
const limit = 500
const iteration = 1
const limit = 500;
console.log(`共有${cnt}条数据`)
console.log(`共有${cnt}条数据`);
for (let offset = 0; offset < cnt; offset += limit) {
console.log(`正在处理offset ${offset}, limit ${limit}`);
while (true) {
const rows = await Repository.findAll({
where: {
// tslint:disable-next-line: no-null-keyword
token: null
},
limit,
offset
});
limit
})
console.log(`正在处理第 ${iteration} 轮, length ${rows.length}`)
if (rows.length === 0) {
console.log('全部处理完成')
break
}
await Promise.all(
rows.map(async repo => {
if (!repo.token) {
repo.token = nanoid(32);
await repo.save();
repo.token = nanoid(32)
await repo.save()
console.log(
chalk.green(repo.name + "添加了默认token" + repo.token)
);
)
}
})
);
)
}
process.exit(0)
})();
})()

Loading…
Cancel
Save