@odla-ai/brand 0.8.5 → 0.8.6

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/dist/index.js CHANGED
@@ -4702,18 +4702,26 @@ function candidateAssetIds(row) {
4702
4702
  }
4703
4703
  async function attachedBrandAssetIds(db, book, row) {
4704
4704
  const candidates = candidateAssetIds(row);
4705
- const assets = await Promise.all(candidates.map(async (id) => {
4706
- const result = await db.query({
4707
- [BRAND_NS.asset]: {
4708
- $: { where: { id, bookId: book.id, status: "live" }, limit: 2 },
4709
- book: { $: { limit: 2 } }
4710
- }
4711
- });
4712
- const rows = result[BRAND_NS.asset] ?? [];
4713
- if (rows.length !== 1) return null;
4714
- const asset = rows[0];
4715
- return asset.id === id && asset.bookId === book.id && asset.status === "live" && asset.deletedAt === void 0 && hasExactOneLink(asset.book, book.id) ? id : null;
4716
- }));
4705
+ if (candidates.length === 0) return [];
4706
+ const result = await db.query({
4707
+ [BRAND_NS.asset]: {
4708
+ $: {
4709
+ where: {
4710
+ id: { $in: candidates },
4711
+ bookId: book.id,
4712
+ status: "live"
4713
+ },
4714
+ limit: candidates.length
4715
+ },
4716
+ book: { $: { limit: 2 } }
4717
+ }
4718
+ });
4719
+ const rows = result[BRAND_NS.asset] ?? [];
4720
+ const byId = new Map(rows.map((asset) => [asset.id, asset]));
4721
+ const assets = candidates.map((id) => {
4722
+ const asset = byId.get(id);
4723
+ return asset && asset.id === id && asset.bookId === book.id && asset.status === "live" && asset.deletedAt === void 0 && hasExactOneLink(asset.book, book.id) ? id : null;
4724
+ });
4717
4725
  return assets.filter((id) => id !== null);
4718
4726
  }
4719
4727