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

Add Octopoes bulk reports API #4219

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Donnype
Copy link
Contributor

@Donnype Donnype commented Mar 26, 2025

Changes

Another performance enhancement for #4007

Issue link

Demo

QA notes

There is no real way to QA the new endpoint now unless we start talking to the Octopoes API directly. However, this will be QA'd once integrated in #4007.


Code Checklist

  • All the commits in this PR are properly PGP-signed and verified.
  • This PR only contains functionality relevant to the issue.
  • I have written unit tests for the changes or fixes I made.
  • I have checked the documentation and made changes where necessary.
  • I have performed a self-review of my code and refactored it to the best of my abilities.

Checklist for code reviewers:

Copy-paste the checklist from the docs/source/templates folder into your comment.


Checklist for QA:

Copy-paste the checklist from the docs/source/templates folder into your comment.

@Donnype Donnype self-assigned this Mar 26, 2025
@Donnype Donnype requested a review from a team as a code owner March 26, 2025 18:03
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
33.8% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@ammar92 ammar92 self-assigned this Mar 28, 2025
Copy link
Contributor

@ammar92 ammar92 left a comment

Choose a reason for hiding this comment

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

Nice optimization. I left a few remarks, let me know if it helps

report_type="concatenated-report",
)
octopoes_api_connector.save_declaration(Declaration(ooi=recipe, valid_time=valid_time))
octopoes_api_connector.save_declaration(Declaration(ooi=report, valid_time=valid_time))
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicate statement?


if not ignore_count:
count_results = self.query(query.count(), valid_time)
count = 0 if not count_results else count_results[0] # type: ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

Why should this type error be ignored? What kind of type error are you getting?

"""
res = self.session.post("/reports", json=reports_filters, params={"valid_time": str(valid_time)})

return TypeAdapter(dict[UUID, HydratedReport]).validate_json(res.content)
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest extracting this TypeAdapter instance to a variable outside the class, since they're quite costly to make. This way the TypeAdapter can be reused

reports = {}

for client, recipe_id in reports_filters:
xtdb_http_client._client = client
Copy link
Contributor

Choose a reason for hiding this comment

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

Accessing a private attribute like this is not Pythonic. Perhaps this attribute can now be a public property instead?

IMO client here is a bit ambiguous. Maybe not for now, but I suggest eventually renaming either the attribute or variable name to organization_code

Comment on lines +30 to +37
The reason for creating the event_manager do this in the loop is the '_try_connect()' call in the __init__ possibly
slowing this down, while this API was introduced to improve performance. Simply reusing it for all clients works
because the event manager is only used in callbacks triggered on a `commit()`, while these queries are read-only and
hence don't need a `commit()` as no events would be triggered. (A cleaner solution would perhaps be to extract an
interface and pass a new NullManager.)

The xtdb_http_client is also created outside the loop and the `_client` property changed inside the loop instead,
to reuse the httpx Session for all requests.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is useful information, but I recommend placing it elsewhere in the method rather than in the docstring. Since the docstring serves as API documentation, this information isn't relevant to API users

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Review
Development

Successfully merging this pull request may close these issues.

2 participants