Skip to content
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

Improve performance for calculating breaches #101

Merged
merged 5 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/100.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improve performance for calculating breaches.
[pgrunewald]
6 changes: 5 additions & 1 deletion plone/app/linkintegrity/browser/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def get_breaches(self, items=None):
# add the current items uid and all its children's uids to the
# list of uids that are ignored
uids_to_ignore.extend([i.UID for i in brains_to_delete])
# prepare the collection of breaches for current item
get_breaches_for_item = None
for brain_to_delete in brains_to_delete:
try:
obj_to_delete = brain_to_delete.getObject() # noqa
Expand All @@ -67,7 +69,9 @@ def get_breaches(self, items=None):
"No object found for %s! Skipping", brain_to_delete
)
continue
for breach in self.get_breaches_for_item(obj):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I read the code correctly but shouldn't this check the breach of the obj_to_delete instead of the obj ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because get_breaches_for_item does collect all the breaches for all the children, see https://github.com/plone/plone.app.linkintegrity/blob/master/plone/app/linkintegrity/browser/info.py#L138-L139.

But then again, obj_to_delete does not really do anything here. Now looking at it, there could be more improvements implemention-wise.

Copy link
Member

@petschki petschki Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch ... I think there is something like "depth": 1 missing in the get_breaches_for_item catalog path query ... otherwise the recursive lookup does things multiple times for the same folder.

Copy link
Contributor Author

@pgrunewald pgrunewald Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. Looking up the same items multiple times is really unnecessary. I will rewrite those parts even further.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petschki I have rewritten a good chunk of the code, while maintaining backwards compatibility. In the Plone code base I just found usages for get_breaches. In case anyone uses in their 3rd party add-on the other methods, they should still be able to do so.

if get_breaches_for_item is None:
get_breaches_for_item = self.get_breaches_for_item(obj)
for breach in get_breaches_for_item:
add_breach = False
for source in breach["sources"]:
# Only add the breach if one the sources is not in the
Expand Down