22378 reshape customscript object column#22574
Conversation
|
@claude /review Only report on issues of potential concern; we don't need commentary on anything that doesn't require further consideration. |
|
Claude finished @jeremystretch's task in 58s —— View job ReviewOne critical bug and one performance concern to address.
except RuntimeException:
Fix: use Per-row database query ( obj = model.objects.get(**match.kwargs)This issues a separate database query for every row in the log table. Scripts that log many objects will produce a large number of queries per page render. Since
|
jeremystretch
left a comment
There was a problem hiding this comment.
I appreciate what you're trying to achieve with this change, but I'm not sure it' feasible from a performance standpoint.
| record['url'], | ||
| value, | ||
| ) | ||
| except RuntimeException: |
There was a problem hiding this comment.
This is an invalid exception, but it also doesn't adequately contain a potential failure. The method will still attempt to reference record['url'], which (per line 820) might not exist.
There was a problem hiding this comment.
My intention was, that if anything goes wrong, the whole function would execute in the same way, it does currently, before my PR.
So if record['url'] is empty, it currently generates a link with empty href…
I fixed the Exception name.
But I noticed, that the if statement is kinda useless if I accept running into an exception anyways, so I removed the if-line for performance reasons.
| if not (hasattr(view_class, "queryset") and hasattr(view_class.queryset, "model")): | ||
| return format_html("<a href='{}'>{}</a>", record['url'], value) | ||
| model = view_class.queryset.model | ||
| obj = model.objects.get(**match.kwargs) |
There was a problem hiding this comment.
We need to avoid potentially triggering an individual query per log line.
There was a problem hiding this comment.
Actually I wanted to go with a change, which has as minimal impact on the current structures as possible.
The suggestion from Claude to injected the parent object information into the log record at write time would go against this, since it would impact the whole log format and therefore breaking backwards compatibility. (Scripts which were run before the change don't possess this information)
The additional query is only done for those log lines, who have set an object in the first place (since render_object() isn't even called when there is no object), therefore IMHO the trade-off regarding the performance does not weigh as heavily in comparison.
- RepairException Name - Move include to top
Closes: #22378
I went for a simple approach, using
parent_objectwhen present. I was thinking about doing the same for.deviceand.group, but wasn't convinced it would help much.I was wondering, if there is some sort of convention on how a parent object should be referred to (see discussion #22403).
Removed the unused
render_url()function as well.