Merge ~jugmac00/launchpad:create-preserving-query-count-how-to into launchpad:master

Proposed by Jürgen Gmach
Status: Merged
Approved by: Jürgen Gmach
Approved revision: 615692361e2157f4b4e5998d7fe182cb95a2a831
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~jugmac00/launchpad:create-preserving-query-count-how-to
Merge into: launchpad:master
Diff against target: 42 lines (+25/-0)
2 files modified
doc/how-to/preserve-query-count.rst (+24/-0)
doc/index.rst (+1/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+416670@code.launchpad.net

Commit message

Create `Preserving query count` how-to

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Needs Fixing
Revision history for this message
Jürgen Gmach (jugmac00) wrote :

Thanks for the review!

I have replaced my example with code using the mentioned `record_two_runs` function.

As `test_getBuildSummariesForSnapBuildIds_query_count` uses both an inline function definition and a context manager, I looked around and found a simpler test function.

If you have a minute, please review again.

Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/doc/how-to/preserve-query-count.rst b/doc/how-to/preserve-query-count.rst
2new file mode 100644
3index 0000000..2b8e180
4--- /dev/null
5+++ b/doc/how-to/preserve-query-count.rst
6@@ -0,0 +1,24 @@
7+======================
8+Preserving query count
9+======================
10+
11+Given you want to read or create many items instead of one,
12+you need to make sure that the number of queries stays constant.
13+
14+In Launchpad this can be done by using `lp.testing.record_two_runs`,
15+as outlined in the following example:
16+
17+.. code-block:: python
18+
19+ def test_view_query_count(self):
20+ # Test that the view bulk loads artifacts.
21+ person = self.factory.makePerson()
22+ pillarperson = PillarPerson(self.pillar, person)
23+ recorder1, recorder2 = record_two_runs(
24+ tested_method=lambda: create_initialized_view(pillarperson, '+index'),
25+ item_creator=lambda: self.makeArtifactGrantee(person, True, True, True, False),
26+ first_round_number=5,
27+ login_method=lambda: login_person(self.owner))
28+ self.assertThat(recorder2, HasQueryCount.byEquality(recorder1))
29+
30+For further information, please have a look at `record_two_runs`' docstring.
31diff --git a/doc/index.rst b/doc/index.rst
32index aad3908..6e7f32e 100644
33--- a/doc/index.rst
34+++ b/doc/index.rst
35@@ -36,6 +36,7 @@ How-to Guides
36 how-to/apply-schema-changes
37 how-to/use-updated-dependency
38 how-to/resurrect-dogfood
39+ how-to/preserve-query-count
40
41 Explanation
42 ===========

Subscribers

People subscribed via source and target branches

to status/vote changes: