Collection size limit
I have a collection of items that'll get created frequently, and I don't need to store them forever, so I want to delete old entries to preserve space.
My current strategy is to delete extra items once the collection size is over some arbitrary max.
I'm not that worried about performance since the collection isn't that big, nor is the limit, but I still wonder if there's a more performant/idiomatic way to accomplish this.
Here's my code:
3 Replies
Re: idiomatic, could be a cron job or a job that gets scheduled to run immediately — could cut down the latency a tiny bit. What you've got here is how I'd do it, curious if others have ideas.
I've used a mix of a cron job or an immediately scheduled job for this for one of my apps. I have a little card game where clicking "end game" essentially schedules a mutation that deletes the cards and other game state I don't need anymore.
I've done the same thing in one or two of my apps