I have about 1000 records in my database that need to be updated every minute. Currently I’m using the update() function. But it takes a long time until each entry is updated:
If someone sends a request to strapi while the code ist running, it takes up to one minute until the user receives a response. Now I’m searching for a better solution.
I think the main problem here is with the spots component. Since updating entries with components takes a longer time.
I would recommend to omit the component and create 3 new fields:
spots__free
spots__freeText
spots__capacity
This will cost you less time to update the entry.
Components are good for static data, like blog articles, static websites and etc. But if you want to update them periodically(in your case every minute) then you should avoid using them.
To display them in API properly as an object, you can write a custom controller with a function that modified the results:
WOW. Thank you! I didn’t know that! That’s much faster!
But requests to my Strapi instance are still a few seconds slower while the code to update the entries is executing. Are you facing the same behavior?
And where to put your example Code? Into the Controller?
No. You need to examine all the requests and what exactly increases the time and tweak them more if you want to gain more speed and still update them very often. What DB do you use, mongo, MySQL, postgres? Is it an external db or it is hosted on the same server with strapi?
Yes, inside the find and findone controllers, so the end-users could get a well-formatted response instead of spots__ fields.
Thank you for the hint! For development I’m using an external DB. But on my production Server, the DB is on the same server and I’m using localhost to establish a connection. There are no performance problems. Now I know what the problem is. Thanks again!