@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.cjs CHANGED
@@ -5794,18 +5794,26 @@ function candidateAssetIds(row) {
5794
5794
  }
5795
5795
  async function attachedBrandAssetIds(db, book, row) {
5796
5796
  const candidates = candidateAssetIds(row);
5797
- const assets = await Promise.all(candidates.map(async (id) => {
5798
- const result = await db.query({
5799
- [BRAND_NS.asset]: {
5800
- $: { where: { id, bookId: book.id, status: "live" }, limit: 2 },
5801
- book: { $: { limit: 2 } }
5802
- }
5803
- });
5804
- const rows = result[BRAND_NS.asset] ?? [];
5805
- if (rows.length !== 1) return null;
5806
- const asset = rows[0];
5807
- return asset.id === id && asset.bookId === book.id && asset.status === "live" && asset.deletedAt === void 0 && hasExactOneLink(asset.book, book.id) ? id : null;
5808
- }));
5797
+ if (candidates.length === 0) return [];
5798
+ const result = await db.query({
5799
+ [BRAND_NS.asset]: {
5800
+ $: {
5801
+ where: {
5802
+ id: { $in: candidates },
5803
+ bookId: book.id,
5804
+ status: "live"
5805
+ },
5806
+ limit: candidates.length
5807
+ },
5808
+ book: { $: { limit: 2 } }
5809
+ }
5810
+ });
5811
+ const rows = result[BRAND_NS.asset] ?? [];
5812
+ const byId = new Map(rows.map((asset) => [asset.id, asset]));
5813
+ const assets = candidates.map((id) => {
5814
+ const asset = byId.get(id);
5815
+ return asset && asset.id === id && asset.bookId === book.id && asset.status === "live" && asset.deletedAt === void 0 && hasExactOneLink(asset.book, book.id) ? id : null;
5816
+ });
5809
5817
  return assets.filter((id) => id !== null);
5810
5818
  }
5811
5819