-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[idea] NoCollectionPKField #19
Comments
Thinking to it, It seems to me that the "collection=False" parameter is a bit more convenient: this allow to use both the PKField of AutoPKField without the collection. By the way, one question is: what to do when, using a model without collection, someone ask for its collection ? Raising ? Returning an empty set ? |
i vote for raising too ! |
@yohanboniface @twidi Interested in how others have solved this problem. At the momnent I've used a Is got a better way? |
A few years after, I am not sure what the idea was. To skip storing the collection in a redis set? For simple collections it would be easy I guess, but for more complex ones, the collection on the redis side is needed because it is used to do many operations on the set. Some time should be spent on it. @glynjackson: any way to see your implementation? |
I think my situation is typical. I had For example,
This results in:
Where For example I used it like this:
So as I know the bucket ID all I need in this case is:
On models where I did not want a collection to be created I add For example one override is:
This took a while on anything that creates a collection. |
@twidi Sorry, I did not look at the date! My bad! But, I guess it's still a requirement. There are lots of times where you already know the ID and don't need a collection set created in limpyd, again! I've only been looking at this today, so I'm not familiar with the package. |
@twidi , sorry to fill up your inbox :) Looking at this more closely, my example is trying to replicate creating a collection in limpyd. I think it would be more appropriate to have something like
Redis:
The Python:
Would something like this be better, possible? |
OH I think I understand know, it's only about the set that stores all the PKs of objects of a model? (which is by the way also used for collections filtering) |
Yep, sorry about my long explanation 👎 . It's because of the dependency on filtering my first example would be a bad idea. However, if we had something like |
I have no time to dig into this right now, sorry :-/ About the filtering, I don't remember if the filtering uses the default collection or not. Also, although I use limpyd very often, I didn't touch the (complex) internals for a while so I'm not able to answer in a more advanced way before intensively digging through the code |
@twidi Thanks regardless, it's a fantastic package. I've only spent a small amount of time digging into it anyhow. I'm sure I can find a good solution. |
Thank you for your kind words :) And good luck! |
Turns out to be easy. I've added a new property called I added a base model which extends
Example of 2 modles, collection and non-collection option: NoCollectionInstance:
CollectionInstance:
Next, override
This allows:
Next, limpyd checks for a PK using the collection set stored in Redis, since my
Above allows the following without any errors:
or any gets,
or deletes,
Last, is the use of the collection manager. Initially, the collection manager was somewhat confusing. I still wanted to use a manager on |
Sometimes, we know that we will always retrieve pk from indexes, other objects (foreign key) or other references (for example a RedisModel linked to a Django model). In these cases, the collection key is useless, and if the we have a huge set of data, this could be a leak of resources.
What we can do?
One idea is a "NoCollectionPKField", which will overwrite the "collection" behaviour.
Another idea could be to add a "collect=False" parameter to the PKField.
The text was updated successfully, but these errors were encountered: