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

Optimise next prev record #791

Merged
merged 9 commits into from Sep 16, 2021
Merged

Optimise next prev record #791

merged 9 commits into from Sep 16, 2021

Conversation

RealOrangeOne
Copy link
Member

Description

Improve performance of next_record and prev_record.

Motivation and Context

Using .instance will run an additional query to get the value for fields which are excluded from history. These properties don't need that, they only need _meta, which is accessible from the .instance_type without running any queries.

By executing fewer queries, the properties get faster. This can be especially important if the columns contain a large amount of data.

How Has This Been Tested?

I've manually applied this patch to a project, but also added relevant unit tests (and fixed an existing one which wasn't running).

Screenshots (if appropriate):

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have run the make format command to format my code
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have added my name and/or github handle to AUTHORS.rst
  • I have added my change to CHANGES.rst
  • All new and existing tests passed.

Previously they called `.instance`, which was unnecessary as only the `_meta` was needed. By using the class itself, the need for an extra query is removed in cases where fields are excluded.
Methods are only run as test cases if they start with `test_`
@codecov
Copy link

codecov bot commented Feb 5, 2021

Codecov Report

Merging #791 (31b9374) into master (c5943f4) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #791      +/-   ##
==========================================
+ Coverage   97.68%   97.69%   +0.01%     
==========================================
  Files          19       19              
  Lines         994      999       +5     
  Branches      151      151              
==========================================
+ Hits          971      976       +5     
  Misses         10       10              
  Partials       13       13              
Impacted Files Coverage Δ
simple_history/manager.py 97.59% <100.00%> (-0.06%) ⬇️
simple_history/models.py 97.86% <100.00%> (ø)
simple_history/utils.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5943f4...31b9374. Read the comment docs.

@RealOrangeOne
Copy link
Member Author

RealOrangeOne commented Feb 5, 2021

Unfortunately it seems this causes issues where history of different models ends up in prev_record etc

Fixed in e250831

@RealOrangeOne RealOrangeOne marked this pull request as draft February 5, 2021 13:23
This means history for another model doesn't appear incorrectly.
@RealOrangeOne RealOrangeOne marked this pull request as ready for review February 5, 2021 15:56
@jeking3
Copy link
Contributor

jeking3 commented Sep 16, 2021

I applied the tests to 3.0.0 (master) and found them to be failing with too many queries, when I applied the changes in the pull request they correctly reduced.

jeking3
jeking3 previously approved these changes Sep 16, 2021
@jeking3 jeking3 merged commit e3065b9 into jazzband:master Sep 16, 2021
@RealOrangeOne RealOrangeOne deleted the optimise-next-prev-record branch September 16, 2021 18:48
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.

None yet

2 participants