I have the following AWS AppSync/Amplify model
type Event @model {
id: ID!
name: String!
ticketsSold: Int!
moneySum: Int!
}
The ticketsSold
property must reflect the count of orders
with eventId = X
. moneySum
must represent a SUM of all the orders ticket price with eventId = X
.
There are 2 options (or more?) to consider:
- With every
putItem
(createOrder mutation), update the correctevent
row with the new count/sum - Do a query/scan of all the orders with
eventId = X
via an AWS Lambda resolver
There are some pro's and con's with each of the options. With option 1 there is the possibility to get out of sync if multiple people order at the same time (transactions?). With option 2 there is the drawback that scanning is very expensive & slow...
The events are shown on the home page of a ReactJS app with the ticketsSold
and moneySum
shown as a preview and on the detail so it will get fetched "a lot".
Suggestions? Thanks a lot!