cvat icon indicating copy to clipboard operation
cvat copied to clipboard

Optimize DB requests in project list, job list, and other endpoints

Open zhiltsov-max opened this issue 6 months ago • 5 comments

Motivation and context

  • Added an option to use the organization instance from the object in question, if provided (many viewsets prefetch this)
  • Removed .first() calls, leading to extra db requests for projects
  • Added prefetch for source and target storages of jobs
  • Optimized calls to related manifests in cloudstorages api (however, manifests should be either moved to a separate endpoint or should be limited in maximum number per CS)
  • Optimized unnecessary DB requests to related models in IAM requests

All this primarily affected GET /api/projects and GET /api/jobs, but other endpoints also benefited from this a little bit.

Examples: 4 projects, > 100 tasks, > 100 jobs

Before: Screenshot from 2024-08-07 18-27-34

Screenshot from 2024-08-07 18-28-00

After: Screenshot from 2024-08-07 18-25-54

Screenshot from 2024-08-07 18-24-19

How has this been tested?

Checklist

  • [ ] I submit my changes into the develop branch
  • [ ] I have created a changelog fragment
  • [ ] I have updated the documentation accordingly
  • [ ] I have added tests to cover my changes
  • [ ] I have linked related issues (see GitHub docs)
  • [ ] I have increased versions of npm packages if it is necessary (cvat-canvas, cvat-core, cvat-data and cvat-ui)

License

  • [ ] I submit my code changes under the same MIT License that covers the project. Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

  • New Features

    • Enhanced performance of data retrieval in views by optimizing related fields in the JobViewSet.
    • Improved handling of organization data in permissions, ensuring more robust checks and reducing unnecessary database queries.
  • Bug Fixes

    • Refined output of serialized data to include only valid task subsets and handle dimensions correctly.
  • Documentation

    • Updates made to improve clarity on serialized responses and organization permission handling.

zhiltsov-max avatar Aug 07 '24 15:08 zhiltsov-max