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

Fix fetch unlabeled detections endpoint #366

Merged
merged 9 commits into from
Nov 1, 2024

Conversation

RonanMorgan
Copy link
Collaborator

When calling the fetch unlabeled detections endpoint with an ADMIN token, the pictures were not found in the S3 because the organisation_id of ADMIN is = 1, while we would like to get all the Detection of all the organization.

So for ADMIN token we should find the organization_id thanks to the Camera.detection_id

Copy link

codecov bot commented Sep 10, 2024

Codecov Report

Attention: Patch coverage is 70.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 84.83%. Comparing base (f737b0d) to head (982c194).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/app/api/api_v1/endpoints/detections.py 80.00% 3 Missing ⚠️
src/app/crud/base.py 50.00% 2 Missing ⚠️
src/app/api/dependencies.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #366      +/-   ##
==========================================
- Coverage   85.51%   84.83%   -0.68%     
==========================================
  Files          35       35              
  Lines         987      996       +9     
==========================================
+ Hits          844      845       +1     
- Misses        143      151       +8     
Flag Coverage Δ
backend 84.35% <70.00%> (-0.72%) ⬇️
client 92.06% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@frgfm frgfm left a comment

Choose a reason for hiding this comment

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

Thanks! I wanted to update the logic here as well, to adapt what I did on old-production (we've benchmarked it with Mateo to avoid veryyyyyyy slow queries). cf. my comments

@@ -165,19 +165,24 @@ async def fetch_unlabeled_detections(
def get_url(detection: Detection) -> str:
return bucket.get_public_url(detection.bucket_key)

async def get_url_with_bucket(detection: Detection) -> str:
camera = cast(Camera, await cameras.get(detection.camera_id, strict=True))
Copy link
Member

Choose a reason for hiding this comment

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

Considering the size of the potential result, this could become quite slow. We've had to solve this on the old-production branch. I suggest taking the same approach : https://github.com/pyronear/pyro-api/blob/old-production/src/app/api/endpoints/events.py#L149

(otherwise if there are 150 detections, we'll have to do 150 invidual camera fetch)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok I have implemented a pagination parameter in the endpoint (and the fetch_all function) is it ok for you ?

Copy link
Member

Choose a reason for hiding this comment

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

On paper yes, but what is implemented on old-production was proofed with platform interactions and extremely fast. Pagination will for sure needed at some point, but for now, for the sake of "let's do what we know works well", I'd suggest taking only adapting that code. If you feel like we should introduce pagination now:

Considering this is only for the platform and for now, it fills that need, I think those param and pagination aren't necessary but I'll let you be the judge of that 👌

Copy link
Member

@frgfm frgfm left a comment

Choose a reason for hiding this comment

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

Thanks! I'm pretty sure everything here works but as mentioned in the comment, I have no clue how fast. This route needs to be really low latency and we've iterated on old-production branch to make something that works. Out of safety, I think we should keep that design 👌

@@ -165,19 +165,24 @@ async def fetch_unlabeled_detections(
def get_url(detection: Detection) -> str:
return bucket.get_public_url(detection.bucket_key)

async def get_url_with_bucket(detection: Detection) -> str:
camera = cast(Camera, await cameras.get(detection.camera_id, strict=True))
Copy link
Member

Choose a reason for hiding this comment

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

On paper yes, but what is implemented on old-production was proofed with platform interactions and extremely fast. Pagination will for sure needed at some point, but for now, for the sake of "let's do what we know works well", I'd suggest taking only adapting that code. If you feel like we should introduce pagination now:

Considering this is only for the platform and for now, it fills that need, I think those param and pagination aren't necessary but I'll let you be the judge of that 👌

@@ -64,8 +64,7 @@ async def create_detection(
# guess_extension will return none if this fails
extension = guess_extension(magic.from_buffer(file.file.read(), mime=True)) or ""
# Concatenate timestamp & hash
bucket_key = f"{token_payload.sub}-{datetime.utcnow().strftime('%Y%m%d%H%M%S')}-{sha_hash[:8]}{extension}"
# Reset byte position of the file (cf. https://fastapi.tiangolo.com/tutorial/request-files/#uploadfile)
bucket_key = f"{token_payload.sub}-{datetime.utcnow().strftime('%Y%m%d%H%M%S')}-{sha_hash[:8]}{extension}" # Reset byte position of the file (cf. https://fastapi.tiangolo.com/tutorial/request-files/#uploadfile)
Copy link
Member

Choose a reason for hiding this comment

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

Can you revert the comment position to the next line as previously? (gonna have formatting errors at some point otherwise)

Ronan and others added 4 commits September 23, 2024 17:09
@frgfm frgfm added the type: fix Something isn't working label Nov 1, 2024
@frgfm frgfm added this to the 0.2.0 milestone Nov 1, 2024
frgfm added 3 commits November 1, 2024 19:33
@frgfm frgfm merged commit 40cda4a into main Nov 1, 2024
26 of 28 checks passed
@frgfm frgfm deleted the rs/fix-fetch-unlabeled-detections branch November 1, 2024 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants