Question

I am looking to find a way to increment the numOfViews field when an item is retrieve from GET, my current approach is hock on the app.on_post_GET_items event and update the field accordingly, is it something we do typically? my concern is this will slow down the 'GET' i.e. read operation as we always 'write' afterward. Do we have a better solution in general?

Was it helpful?

Solution

If performance is a concern you should consider using Redis, or something like that, to store this sort of frequently updating data. You could then reconcile with the database when appropriate (idle moments, etc.).

This being said, since you are writing to the database after the response has been sent, you aren't actively delaying the response (something you would do if you hooked to the on_fetch event instead).

I guess it all depends on 1) the kind of traffic your API is going to handle and 2) where you are storing these stats. If you are going to get a lot of traffic (or want to be ready for it), then consider using an alternate storage (possibly in memory) other than your main database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top