0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Removed duplicate serialization for offers

- we can skip an extra `toJSON` call here by storing the value and
  re-using it, which means we can cut down on the number of calls, which
  can be particularly heavy when this codepath is hit hard
This commit is contained in:
Daniel Lockyer 2024-11-04 20:47:41 +01:00 committed by Daniel Lockyer
parent 19f6f910b6
commit 44edf3d379

View file

@ -107,6 +107,8 @@ class OfferBookshelfRepository {
}); });
try { try {
const lastRedeemedObject = lastRedeemed.toJSON();
return await Offer.create({ return await Offer.create({
id: json.id, id: json.id,
name: json.name, name: json.name,
@ -126,7 +128,7 @@ class OfferBookshelfRepository {
name: json.product.name name: json.product.name
}, },
created_at: json.created_at, created_at: json.created_at,
last_redeemed: lastRedeemed.toJSON().length > 0 ? lastRedeemed.toJSON()[0].created_at : null last_redeemed: lastRedeemedObject.length > 0 ? lastRedeemedObject[0].created_at : null
}, null); }, null);
} catch (err) { } catch (err) {
logger.error(err); logger.error(err);