j3k0 commented on issue #4462:
URL: https://github.com/apache/couchdb/issues/4462#issuecomment-1463936020
Sure, a simplified pseudo example (our actual views are hundreds of lines)
Context: an "events" database that contains the interactions (REST and
Webhook calls) with various payment providers.
We want to emit the history of states for all transactions.
## Before updating the design document
```js
function (event) {
switch (event.type) {
case "appstore.webhook":
event.appleTransactions.forEach(function(appleTransaction) {
emit([appleTransaction.id, event.date],
appleTransaction.transactionState);
}); break;
case "appstore.verifyReceipt":
// handle specific data stored in "apple.verifyReceipt" events.
}
}
```
## After updating the design document
Now we want to add support for Google Play to our system.
```js
function (event) {
switch (event.type) {
// UNCHANGED
case "appstore.webhook":
event.appleTransactions.forEach(function(appleTransaction) {
emit([appleTransaction.id, event.date],
appleTransaction.transactionState);
}); break;
case "appstore.verifyReceipt":
// handle specific data stored in "apple.verifyReceipt" events.
// +++ ADDITION HERE +++ we add support for google-play-style
server-to-server notifications.
case "googleplay.notification":
emit([event.googlePurchase.purchaseToken, event.date],
event.googleNotification.type);
break;
// and more event types...
}
}
```
We could in principle redeploy this view to production without recomputing
the index, because there's no event with `type: "googleplay.notification"` in
the database yet. Note: our DB is 5TB and it contains 500M documents.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]