gstore-node icon indicating copy to clipboard operation
gstore-node copied to clipboard

Feature request: Utility method for counting entities.

Open huysamen opened this issue 6 years ago • 3 comments

Like the .list() method, but maybe just select the keys and return the count. I will try and do the implementation sometime and make a PR.

huysamen avatar Sep 11 '18 06:09 huysamen

Hello, I am not sure this would be the best practice to implement a counter. I would go either by saving the entities in an entity group under an ancestor entity that has a count property (an update this count property in a transaction when creating or deleting an entity). If there is a lot of write I would go with a sharding counter (https://cloud.google.com/appengine/articles/sharding_counters) What do you think?

sebelga avatar Sep 11 '18 10:09 sebelga

I have to agree with Sébastien.

Although I don't think there is harm in having a basic counter query implemented into the library for convenience sake, I don't think using this technique is the most efficient for most Datastore use cases. But then again, it entirely depends on how your business data is structured and how the developer decides is the best way to handle it.

That being said, I do think it's worth adding basic counter to the library because it is only a negligible amount of code, but adds for a pretty convenient feature for those that need it.

On Tue, Sep 11, 2018, 6:29 AM Sébastien Loix [email protected] wrote:

Hello, I am not sure this would be the best practice to implement a counter. I would go either by saving the entities in an entity group under an ancestor entity that has a count property (an update this count property in a transaction when creating or deleting an entity). If there is a lot of write I would go with a sharding counter ( https://cloud.google.com/appengine/articles/sharding_counters) What do you think?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sebelga/gstore-node/issues/126#issuecomment-420225887, or mute the thread https://github.com/notifications/unsubscribe-auth/AGOnw1j2HMKAcbGnlasYOZ4GmKOsh8Vbks5uZ5BsgaJpZM4WitGE .

micaww avatar Sep 11 '18 19:09 micaww

Yeah, I am not against adding a utiliy helper for a counter like @huysamen suggests. I think we would then need to indicate in the Docs other options that might be more efficient according to the use cases.

sebelga avatar Sep 12 '18 10:09 sebelga