codeant-ai-for-open-source[bot] commented on code in PR #46045:
URL: https://github.com/apache/superset/pull/46045#discussion_r4487503727
##########
superset/daos/dataset.py:
##########
@@ -192,8 +191,64 @@ def get_related_objects_for_datasets(dataset_ids:
list[int]) -> dict[str, Any]:
.distinct()
.all()
)
+ seen_ids = {dashboard.id for dashboard in dashboards}
+ extra_ids = [
+ dashboard_id
+ for dashboard_id in DatasetDAO._dashboard_ids_targeting_datasets(
+ dataset_ids
+ )
+ if dashboard_id not in seen_ids
+ ]
+ if extra_ids:
+ dashboards.extend(
+
db.session.query(Dashboard).filter(Dashboard.id.in_(extra_ids)).all()
+ )
return {"charts": charts, "dashboards": dashboards}
+ @staticmethod
+ def get_charts_for_datasets(dataset_ids: list[int]) -> list[Slice]:
+ """
+ Return the charts built on any of the datasets. Callers that only need
+ charts should use this rather than ``get_related_objects``, which also
+ scans dashboard metadata.
+ """
+ if not dataset_ids:
+ return []
+ return (
+ db.session.query(Slice)
+ .filter(
+ Slice.datasource_id.in_(dataset_ids),
+ Slice.datasource_type == DatasourceType.TABLE,
+ )
+ .all()
+ )
+
+ @staticmethod
+ def _dashboard_ids_targeting_datasets(dataset_ids: list[int]) -> list[int]:
+ """
+ Ids of the dashboards whose native filters or display controls target
+ any of the datasets.
+
+ Targets live in ``json_metadata`` text, so a cheap ``LIKE`` prefilter
+ narrows the rows and the parsed metadata is then checked exactly.
+ Dashboards with missing or malformed metadata never match.
+ """
+ wanted = set(dataset_ids)
+ rows = (
+ db.session.query(Dashboard.id, Dashboard.json_metadata)
+ .filter(
+ Dashboard.json_metadata.like('%"datasetId"%'),
+ Dashboard.deleted_at.is_(None),
+ )
+ .order_by(Dashboard.id)
+ .all()
+ )
Review Comment:
**Suggestion:** The leading-wildcard `LIKE` cannot use a normal index, so
each lookup scans and materializes matching dashboard metadata, then parses it
in Python; cost grows with dashboard count.
**Assessment:** ๐ `Major` ยท ๐ `Occurrence: Sometimes` ยท ๐ท๏ธ `Performance`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=d4bab9934f5041159cec93931b31faca&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=d4bab9934f5041159cec93931b31faca&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent ๐ค </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/daos/dataset.py
**Line:** 237:245
**Comment:**
*Performance: The leading-wildcard `LIKE` cannot use a normal index, so
each lookup scans and materializes matching dashboard metadata, then parses it
in Python; cost grows with dashboard count.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F46045&comment_hash=4a01e229b45a4be86a6d1aeebb4700581b457728d6644586855d2345bf8a420b&reaction=like'>๐</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F46045&comment_hash=4a01e229b45a4be86a6d1aeebb4700581b457728d6644586855d2345bf8a420b&reaction=dislike'>๐</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]