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

Speed up annotation list #7410

Merged
merged 29 commits into from
Dec 6, 2023
Merged

Speed up annotation list #7410

merged 29 commits into from
Dec 6, 2023

Conversation

frcroth
Copy link
Member

@frcroth frcroth commented Oct 25, 2023

URL of deployed dev instance (used for testing):

  • https://___.webknossos.xyz

Steps to test:

  • test the annotations list in the dashboard
  • view an annotation
  • download an annotation from the list
  • some monkey-testing

TODOs:

Issues:


(Please delete unneeded items, merge only when none are left open)

@philippotto
Copy link
Member

@frcroth In the front-end, we already distinguished between the types APIAnnotation (e.g., returned by /api/annotations/${annotationId}/info) and APIAnnotationCompact (e.g., returned by /api/users/${userId}/annotations).

How is this distinguished/named in the back-end? Should I handle it like this in the front-end?

  • keep APIAnnotation
  • rename APIAnnotationCompact to APIAnnotationInfo
  • add APIAnnotationInfoCompact

Or am I getting this wrong?

@frcroth
Copy link
Member Author

frcroth commented Oct 30, 2023

Yes, it seems there are now 3 degrees of compactness, full, somewhat compact from list and compact from list query with compact query set.

* keep `APIAnnotation`

* rename `APIAnnotationCompact` to `APIAnnotationInfo`

* add `APIAnnotationInfoCompact`

This seems sensible to me.

@philippotto
Copy link
Member

@frcroth I noticed that the owner and team properties are flattened into the new compact type like this:

ownerId: ObjectId,
ownerFirstName: String,
ownerLastName: String,
teamId: ObjectId,
teamName: String,
teamOrganizationId: ObjectId,

Could you nest them like this so that it matches the format of the existing APIAnnotationInfo?

owner: {
  id: ObjectId,
  firstName: String,
  lastName: String,
},
team: {
  id: ObjectId,
  name: String,
  organizationId: ObjectId,
}

Also I'm wondering why the team property is not an array (and then teams)? I think, an annotation can have multiple teams assigned? At least, the existing APIAnnotationInfo type is defined like this.

@philippotto
Copy link
Member

Also I noticed that the route GET /annotations/shared controllers.AnnotationController.sharedAnnotations() is not used by the front-end anymore. Maybe it's a good idea to remove the back-end related code for that.

@philippotto
Copy link
Member

Also, statistics should be named stats (as it's done in APIAnnotationInfo).

@philippotto
Copy link
Member

And I'm afraid, we need the tags property, as well. The good news is that formattedHash seems to be unused in the front-end. So, that could be removed altogether.

@philippotto
Copy link
Member

Sorry for the peu á peu messaging. state is also required. I hope this is the last missing piece.

Also, when downloading an annotation, we currently check whether the annotation has a volume layer. This information could be found out via an additional request, though. So, no need to change anything for now.

@frcroth
Copy link
Member Author

frcroth commented Nov 6, 2023

@philippotto I renamed stats and added state, tags and the correct teams. Is the non-compact list still useful? otherwise I could also remove that code path.

@philippotto
Copy link
Member

@philippotto I renamed stats and added state, tags and the correct teams.

Great 👍 I integrated it and the dashboard works now.

Is the non-compact list still useful? otherwise I could also remove that code path.

Yes, it can be removed and I think we should do this to reduce complexity. These routes should then return the compact annotation version, too:

  • /api/user/annotations
  • /api/users/${userId}/annotations

After removal, the compact GET parameter shouldn't exist, anymore.

@philippotto
Copy link
Member

Yes, it can be removed and I think we should do this to reduce complexity.

We need to check compatibility with wklibs, too. @fm3 can give insights probably, since he just reworked the client in wklibs.

@fm3
Copy link
Member

fm3 commented Nov 15, 2023

Good point! That’s true, this would be a breaking change for the libs. scalableminds/webknossos-libs#948 makes the libs use versioned api routes. This means that we can support the old case by supplying the older version in the LegacyApiController. However, many users might not yet have adopted to that new libs version. Let’s wait some time before introducing this kind of breaking change. I’d say in this PR it would be best to have this be opt-in only.

@frcroth
Copy link
Member Author

frcroth commented Nov 15, 2023

Good point! That’s true, this would be a breaking change for the libs. scalableminds/webknossos-libs#948 makes the libs use versioned api routes. This means that we can support the old case by supplying the older version in the LegacyApiController. However, many users might not yet have adopted to that new libs version. Let’s wait some time before introducing this kind of breaking change. I’d say in this PR it would be best to have this be opt-in only.

I think it wouldn't be difficult to adapt this so that everything that was returned in the previous non-compact way is now also part of the compact path (and still use only one query). In that case, the old way could be removed, couldn't it?
I think the only relevant things missing are annotation layers and org.

@fm3
Copy link
Member

fm3 commented Nov 15, 2023

sounds fair, yes

@philippotto
Copy link
Member

Ok, then, I'd suggest to do the comparison between single-sql-statement-with-layers-and-org and single-sql-statement-without-layers-and-org to decide whether it's okay to always include layers and organization.

Just tested it, no measurable difference for my test instance (of course I only have one organization etc).

Ok, great 👍 Then, let's keep it simple and just go with one type. I cleaned up the front-end and undid the unnecessary changes. I took the opportunity and renamed the APIAnnotationCompact type to APIAnnotationInfo to match the back-end's nomenclature better. Let me know in case you need something else from the front-end.

@frcroth
Copy link
Member Author

frcroth commented Nov 27, 2023

Ok, then, I'd suggest to do the comparison between single-sql-statement-with-layers-and-org and single-sql-statement-without-layers-and-org to decide whether it's okay to always include layers and organization.

Just tested it, no measurable difference for my test instance (of course I only have one organization etc).

Ok, great 👍 Then, let's keep it simple and just go with one type. I cleaned up the front-end and undid the unnecessary changes. I took the opportunity and renamed the APIAnnotationCompact type to APIAnnotationInfo to match the back-end's nomenclature better. Let me know in case you need something else from the front-end.

Nice! I think you could assign someone for frontend review then if you believe the changes are non-trivial.

@frcroth frcroth changed the title WIP: Speed up annotation list Speed up annotation list Nov 27, 2023
@frcroth frcroth requested a review from fm3 November 27, 2023 10:16
@frcroth frcroth marked this pull request as ready for review November 27, 2023 10:16
…nds/webknossos into compact-annotation-list-query
Copy link
Member

@fm3 fm3 left a comment

Choose a reason for hiding this comment

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

Nice 😎 Please see my small comments

CHANGELOG.unreleased.md Outdated Show resolved Hide resolved
app/models/annotation/Annotation.scala Show resolved Hide resolved
app/models/annotation/Annotation.scala Outdated Show resolved Hide resolved
app/models/annotation/Annotation.scala Show resolved Hide resolved
app/models/annotation/AnnotationService.scala Outdated Show resolved Hide resolved
conf/webknossos.latest.routes Show resolved Hide resolved
@frcroth frcroth requested a review from fm3 November 29, 2023 08:44
Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer left a comment

Choose a reason for hiding this comment

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

Frontend LGTM and I did not find any bugs during testing with the dev instance.

Copy link
Member

@fm3 fm3 left a comment

Choose a reason for hiding this comment

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

Looks like the formattedHash field is missing, which is why the snapshot tests fail. Is this field used somewhere? Should we just refresh the snapshots? The libs client does not use it

@fm3
Copy link
Member

fm3 commented Nov 30, 2023

@MichaelBuessemeyer Note that since the CI wasn’t green recently, maybe the dev instance you tested on was outdated

@MichaelBuessemeyer
Copy link
Contributor

Looks like the formattedHash field is missing, which is why the snapshot tests fail. Is this field used somewhere? Should we just refresh the snapshots? The libs client does not use it

Yes it seems like it is not needed anymore: #7410 (comment)

And I'm afraid, we need the tags property, as well. The good news is that formattedHash seems to be unused in the front-end. So, that could be removed altogether.

@MichaelBuessemeyer Note that since the CI wasn’t green recently, maybe the dev instance you tested on was outdated

Oh, thanks for the notice. I should do a quick retest once the CI is green again 👍

@fm3
Copy link
Member

fm3 commented Dec 4, 2023

@MichaelBuessemeyer I just installed the new version as a dev instance :)

@MichaelBuessemeyer
Copy link
Contributor

I just installed the new version as a dev instance :)

Thanks 🙏.
I did not find any issues 🚀

@frcroth frcroth requested a review from fm3 December 6, 2023 08:13
@frcroth frcroth mentioned this pull request Dec 6, 2023
3 tasks
@frcroth frcroth merged commit 5d7cc66 into master Dec 6, 2023
2 checks passed
@frcroth frcroth deleted the compact-annotation-list-query branch December 6, 2023 09:54
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.

Speed up Annotation List Request
5 participants