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.
Files changed (2) hide show
  1. package/lib/core.js +9 -4
  2. 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
- const batchSize = 100;
62
- for (let i = 0; i < data.length; i += batchSize) {
63
- await ctx.database.upsert('blacklist_users', data.slice(i, i + batchSize));
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') {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-blacklist-online",
3
3
  "description": "自用插件",
4
- "version": "0.1.2",
4
+ "version": "0.1.3",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [