launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #28198
[Merge] ~jugmac00/launchpad:create-preserving-query-count-how-to into launchpad:master
Jürgen Gmach has proposed merging ~jugmac00/launchpad:create-preserving-query-count-how-to into launchpad:master.
Commit message:
Create `Preserving query count` how-to
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~jugmac00/launchpad/+git/launchpad/+merge/416670
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~jugmac00/launchpad:create-preserving-query-count-how-to into launchpad:master.
diff --git a/doc/how-to/preserve-query-count.rst b/doc/how-to/preserve-query-count.rst
new file mode 100644
index 0000000..c36197f
--- /dev/null
+++ b/doc/how-to/preserve-query-count.rst
@@ -0,0 +1,19 @@
+======================
+Preserving query count
+======================
+
+Given you want to read or create many items instead of one,
+you need to make sure that the number of queries stays constant.
+
+In Launchpad this can be done by using the `StormStatementRecorder`,
+as outlined in the following example:
+
+.. code-block:: python
+
+ def test_newNamedAuthTokens_query_count(self):
+ ...
+ with StormStatementRecorder() as recorder1:
+ self.private_ppa.newNamedAuthTokens("tok1")
+ with StormStatementRecorder() as recorder2:
+ self.private_ppa.newNamedAuthTokens(("tok1", "tok2", "tok3"))
+ self.assertThat(recorder2, HasQueryCount.byEquality(recorder1))
diff --git a/doc/index.rst b/doc/index.rst
index f967be6..d3407ce 100644
--- a/doc/index.rst
+++ b/doc/index.rst
@@ -35,6 +35,7 @@ How-to Guides
how-to/avoid-debugging-issues
how-to/apply-schema-changes
how-to/use-updated-dependency
+ how-to/preserve-query-count
Explanation
===========