koishi-plugin-best-cave 2.7.8 → 2.7.9

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/index.js +14 -27
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -722,42 +722,29 @@ var HashManager = class {
722
722
  if (requireAdmin(session, this.config)) return requireAdmin(session, this.config);
723
723
  try {
724
724
  const allCaves = await this.ctx.database.get("cave", { status: "active" });
725
- if (allCaves.length === 0) return "无需补全回声洞哈希";
726
- await session.send(`开始补全 ${allCaves.length} 个回声洞的哈希...`);
727
- const existingHashes = await this.ctx.database.get("cave_hash", {});
728
- const existingHashSet = new Set(existingHashes.map((h4) => `${h4.cave}-${h4.hash}-${h4.type}`));
729
- let hashesToInsert = [];
725
+ const existingHashes = await this.ctx.database.get("cave_hash", {}, { fields: ["cave"] });
726
+ const hashedCaveIds = new Set(existingHashes.map((h4) => h4.cave));
727
+ const cavesToProcess = allCaves.filter((cave2) => !hashedCaveIds.has(cave2.id));
728
+ if (cavesToProcess.length === 0) return "无需补全回声洞哈希";
729
+ await session.send(`开始补全 ${cavesToProcess.length} 个回声洞的哈希...`);
730
+ const hashesToInsert = [];
730
731
  let processedCaveCount = 0;
731
- let totalHashesGenerated = 0;
732
732
  let errorCount = 0;
733
- const flushBatch = /* @__PURE__ */ __name(async () => {
734
- if (hashesToInsert.length === 0) return;
735
- await this.ctx.database.upsert("cave_hash", hashesToInsert);
736
- totalHashesGenerated += hashesToInsert.length;
737
- this.logger.info(`[${processedCaveCount}/${allCaves.length}] 正在导入 ${hashesToInsert.length} 条回声洞哈希...`);
738
- hashesToInsert = [];
739
- }, "flushBatch");
740
- for (const cave2 of allCaves) {
733
+ for (const cave2 of cavesToProcess) {
741
734
  processedCaveCount++;
742
735
  try {
743
736
  const newHashesForCave = await this.generateAllHashesForCave(cave2);
744
- for (const hashObj of newHashesForCave) {
745
- const uniqueKey = `${hashObj.cave}-${hashObj.hash}-${hashObj.type}`;
746
- if (!existingHashSet.has(uniqueKey)) {
747
- hashesToInsert.push(hashObj);
748
- existingHashSet.add(uniqueKey);
749
- }
750
- }
751
- if (hashesToInsert.length >= 100) await flushBatch();
737
+ if (newHashesForCave.length > 0) hashesToInsert.push(...newHashesForCave);
752
738
  } catch (error) {
753
739
  errorCount++;
754
740
  this.logger.warn(`补全回声洞(${cave2.id})哈希时出错: ${error.message}`);
755
741
  }
756
742
  }
757
- await flushBatch();
758
- return `已补全 ${allCaves.length} 个回声洞的 ${totalHashesGenerated} 条哈希(失败 ${errorCount} 条)`;
743
+ if (hashesToInsert.length > 0) await this.ctx.database.upsert("cave_hash", hashesToInsert);
744
+ const successCount = processedCaveCount - errorCount;
745
+ return `已补全 ${successCount} 个回声洞的 ${hashesToInsert.length} 条哈希(失败 ${errorCount} 条)`;
759
746
  } catch (error) {
760
- this.logger.error("生成哈希失败:", error);
747
+ this.logger.error("补全哈希失败:", error);
761
748
  return `操作失败: ${error.message}`;
762
749
  }
763
750
  });
@@ -821,13 +808,13 @@ var HashManager = class {
821
808
  if (requireAdmin(session, this.config)) return requireAdmin(session, this.config);
822
809
  let cavesToProcess;
823
810
  try {
811
+ await session.send("正在修复,请稍候...");
824
812
  if (ids.length === 0) {
825
- await session.send("正在修复,请稍候...");
826
813
  cavesToProcess = await this.ctx.database.get("cave", { status: "active" });
827
814
  } else {
828
815
  cavesToProcess = await this.ctx.database.get("cave", { id: { $in: ids }, status: "active" });
829
816
  }
830
- if (!cavesToProcess.length) return "无可修复回声洞";
817
+ if (!cavesToProcess.length) return "无可修复的回声洞";
831
818
  let fixedFiles = 0;
832
819
  let errorCount = 0;
833
820
  const PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-best-cave",
3
3
  "description": "功能强大、高度可定制的回声洞。支持丰富的媒体类型、内容查重、人工审核、用户昵称、数据迁移以及本地/S3 双重文件存储后端。",
4
- "version": "2.7.8",
4
+ "version": "2.7.9",
5
5
  "contributors": [
6
6
  "Yis_Rime <yis_rime@outlook.com>"
7
7
  ],