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

Don't save all fields of a model when bumping the update date #7450

Merged
merged 4 commits into from
Feb 16, 2024

Conversation

SpecLad
Copy link
Contributor

@SpecLad SpecLad commented Feb 7, 2024

Motivation and context

Currently, there are a lot of places where changing one object requires updating the updated_date field on other objects. Usually, the .save method is used for this purpose, which results in a generic SQL UPDATE query that replaces the values in all columns.

Introduce and use a specialized method that only changes the date. This provides the following advantages:

  • Prevents the date updates from overwriting updates to other fields that may happen at the same time.

  • Possibly makes the updates more efficient due to fewer columns being updated (I have no data on this, though).

  • Makes it easier to recognize the purpose of the query when analyzing logs/live statistics.

  • Makes the purpose of the code more obvious.

Additionally, update __save_job_handler, where we don't want to save just the date, but we still only need to save two fields.

How has this been tested?

I verified that when you save the annotations for a job, only the updated_date field of the task is modified.

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.

cvat/apps/dataset_manager/task.py Show resolved Hide resolved
cvat/apps/engine/views.py Outdated Show resolved Hide resolved
cvat/apps/engine/models.py Show resolved Hide resolved
Instead, use a specialized method that only changes the date. This
provides the following advantages:

* Prevents the date updates from overwriting updates to other fields that
  may happen at the same time.

* Possibly makes the updates more efficient due to fewer columns being
  updated (I have no data on this, though).

* Makes it easier to recognize the purpose of the query when analyzing
  logs/live statistics.

* Makes the purpose of the code more obvious.

The name of the method references the standard POSIX touch utility.
This seems to be in line with the intention of the method. This also
fixes the bug where the job wasn't touched if annotations were cleared
but new ones weren't created.
Copy link

codecov bot commented Feb 15, 2024

Codecov Report

Merging #7450 (389d7c1) into develop (e8384f8) will decrease coverage by 0.04%.
Report is 2 commits behind head on develop.
The diff coverage is 94.59%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7450      +/-   ##
===========================================
- Coverage    83.55%   83.51%   -0.04%     
===========================================
  Files          375      373       -2     
  Lines        39752    39672      -80     
  Branches      3734     3718      -16     
===========================================
- Hits         33213    33131      -82     
- Misses        6539     6541       +2     
Components Coverage Δ
cvat-ui 79.38% <ø> (-0.08%) ⬇️
cvat-server 87.31% <94.59%> (-0.02%) ⬇️

@SpecLad SpecLad merged commit 9c048f2 into cvat-ai:develop Feb 16, 2024
34 checks passed
@SpecLad SpecLad deleted the touch-date branch February 16, 2024 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants