koishi-plugin-blacklist-online 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core.js +9 -4
- package/package.json +1 -1
package/lib/core.js
CHANGED
|
@@ -57,10 +57,15 @@ async function syncBlacklist(ctx, config) {
|
|
|
57
57
|
if (strategy === 'full_replace') {
|
|
58
58
|
logger.info(`📥 全量同步 -> ${newRevision} (条数: ${data.length})`);
|
|
59
59
|
await ctx.database.remove('blacklist_users', {});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
if (data.length > 0) {
|
|
61
|
+
// 修复:使用 upsert 明确告知数据库如果主键冲突则更新
|
|
62
|
+
// 注意:Koishi 的 upsert 在处理大量数据时,建议分批以保证稳定性
|
|
63
|
+
const batchSize = 50;
|
|
64
|
+
for (let i = 0; i < data.length; i += batchSize) {
|
|
65
|
+
const batch = data.slice(i, i + batchSize);
|
|
66
|
+
// 这里的字段名必须与后端返回的 snake_case 保持完全一致
|
|
67
|
+
await ctx.database.upsert('blacklist_users', batch);
|
|
68
|
+
}
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
71
|
else if (strategy === 'incremental') {
|