await Promise.all(
args.storageIds.map(async (s) => {
const metadata = await ctx.db.system.get(s.storageId as Id<"_storage">)
console.log(
"π ~ file: images.ts:43 ~ args.storageIds.map ~ metadata:",
metadata.size
) // 93558, 68153, 68948
const usage = await ctx.db
.query("usage")
.withIndex("by_userId", (q) => q.eq("userId", ctx.userId))
.unique()
console.log(
"π ~ file: images.ts:53 ~ args.storageIds.map ~ usage:",
usage.used
) // 0, 0, 0, should be 0, 93558, 93558 + 68153
await ctx.db.patch(usage._id, { used: usage.used + metadata.size })
await ctx.db.insert("images", {
userId: ctx.userId,
uploadedImageId: s.storageId,
})
})
)
await Promise.all(
args.storageIds.map(async (s) => {
const metadata = await ctx.db.system.get(s.storageId as Id<"_storage">)
console.log(
"π ~ file: images.ts:43 ~ args.storageIds.map ~ metadata:",
metadata.size
) // 93558, 68153, 68948
const usage = await ctx.db
.query("usage")
.withIndex("by_userId", (q) => q.eq("userId", ctx.userId))
.unique()
console.log(
"π ~ file: images.ts:53 ~ args.storageIds.map ~ usage:",
usage.used
) // 0, 0, 0, should be 0, 93558, 93558 + 68153
await ctx.db.patch(usage._id, { used: usage.used + metadata.size })
await ctx.db.insert("images", {
userId: ctx.userId,
uploadedImageId: s.storageId,
})
})
)