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
CMSPlugin.is_last_in_placeholder #1302
Comments
A Great example of the perils of leaning on the ORM too much. Firstly, this function will fill it's cache with all attributes of every plugin in that placeholder, then it will check just the pk of the first object. I really hope this function isn't used by anyone. A better solution would be
That way, the database can calculate the result on it's side (better queryplan), reduce data transfered over network, and get the answer quicker. |
fixed in e6402af |
@czpython Your fix does nothing to address the terrible, terrible O(n^2) performance of this function. Please consider changing the line to read either
OR
|
I don't understand how this is O(n^2), it's a single database query using indexes. Please profile it and show the results. |
As @czpython said, this isn't O(n^2). Also the method clearly states in it's docstring that it's an expensive operation and further this is an undocumented API. As such, I'm more than happy with the patch that fixed the bug. If you want to propose a more efficient way of solving this, please open a new ticket. |
@czpython You are right, it is not on it's own O( n^2 ) but using it can be. Consider an example of a page with a placeholder which has 10 plugins inside of it.
( I know that it's a completely synthetic worst case but where else would you use a function like this?) Then for each of those 10 plugins on the page, you are calling this function which retrieves 10 rows from the database and throws away everything but 1 single value. That makes 100 rows retrieved or ~O( n^2 ) performance hit just for trying to annotate whether we're last in the placeholder. At least by attaching ( I also know that I'm being anal retentive over nothing but I'm currently slogging through someone else's code that uses the simplest possible ORM calls and it's driving me insane how slow it makes everything when these functions with small performance penalties are then called in a loop. Death by a thousand cuts. And everything in cms is just so well optimised everywhere else. I'll just shut up about it now, I promise. ) |
The function
from cms.models.CMSPlugin returns true, if a plugin is the last Placeholder in a plugin. But it counts all Plugins in the placeholder, even the inline plugins.
I don
t think, this is what somebody who calls the function expects (I didn
t).Maybe it would be a good idea, to pass a countinline=false parameter to the function...
The text was updated successfully, but these errors were encountered: