-
Notifications
You must be signed in to change notification settings - Fork 29
DOCSP-45110: queries subsections #80
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,93 @@ | ||||||||||||
.. _mongoid-query-async: | ||||||||||||
|
||||||||||||
==================== | ||||||||||||
Asynchronous Queries | ||||||||||||
==================== | ||||||||||||
|
||||||||||||
.. facet:: | ||||||||||||
:name: genre | ||||||||||||
:values: reference | ||||||||||||
|
||||||||||||
.. meta:: | ||||||||||||
:keywords: ruby framework, odm, memory, background tasks, execution | ||||||||||||
|
||||||||||||
.. contents:: On this page | ||||||||||||
:local: | ||||||||||||
:backlinks: none | ||||||||||||
:depth: 2 | ||||||||||||
:class: singlecol | ||||||||||||
|
||||||||||||
Overview | ||||||||||||
-------- | ||||||||||||
|
||||||||||||
In this guide, you can learn how to perform asynchronous queries in | ||||||||||||
{+odm+}. You can run database queries asynchronously in the background, | ||||||||||||
which can be beneficial if your application retrieves documents from | ||||||||||||
multiple collections. | ||||||||||||
|
||||||||||||
Run Async Queries | ||||||||||||
----------------- | ||||||||||||
|
||||||||||||
To schedule an asynchronous query, call the ``load_async`` method on | ||||||||||||
a ``Criteria`` instance, as shown in the following code: | ||||||||||||
|
||||||||||||
.. code-block:: ruby | ||||||||||||
|
||||||||||||
@active_bands = Band.where(active: true).load_async | ||||||||||||
@public_articles = Article.where(public: true).load_async | ||||||||||||
|
||||||||||||
The preceding code schedules the queries for asynchronous execution. | ||||||||||||
You can then access the results of the queries in your view as you | ||||||||||||
normally do for synchronous queries. | ||||||||||||
|
||||||||||||
Even if a query is scheduled for asynchronous execution, it might be | ||||||||||||
executed synchronously on the caller's thread. The following list | ||||||||||||
describes possible scenarios that this might occur depending on when the | ||||||||||||
query results are being accessed: | ||||||||||||
|
executed synchronously on the caller's thread. The following list | |
describes possible scenarios that this might occur depending on when the | |
query results are being accessed: | |
executed synchronously on the caller's thread. The following list | |
describes possible scenarios that this might occur: |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: is this list exhaustive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure - taken from the original text. But the introduction to this list doesn't give the impression that it is exhuastive "possible scenarios"
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: Can you convert some of these from passive to active voice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: I'm not familiar with this method - how is this similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to_a
performs a conversion to an array of documents, i believe that this forces query execution because it requires the query to return documents to convert those documents to an array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, if you don't call to_a
you're not actually sending the command to the server and just returning an instance of Mongoid::Criteria
instead
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,105 @@ | ||||||||||||
.. _mongoid-query-cache: | ||||||||||||
|
||||||||||||
=========== | ||||||||||||
Query Cache | ||||||||||||
=========== | ||||||||||||
|
||||||||||||
.. facet:: | ||||||||||||
:name: genre | ||||||||||||
:values: reference | ||||||||||||
|
||||||||||||
.. meta:: | ||||||||||||
:keywords: ruby framework, odm, memory, storage, execution | ||||||||||||
|
||||||||||||
.. contents:: On this page | ||||||||||||
:local: | ||||||||||||
:backlinks: none | ||||||||||||
:depth: 2 | ||||||||||||
:class: singlecol | ||||||||||||
|
||||||||||||
Overview | ||||||||||||
-------- | ||||||||||||
|
||||||||||||
In this guide, you can learn about **query caching**. The | ||||||||||||
query cache saves the results of previous find and aggregation queries | ||||||||||||
and reuses them in the future. This prevents {+odm+} from performing | ||||||||||||
the queries again, increasing application performance and reducing | ||||||||||||
the database load. | ||||||||||||
|
||||||||||||
To learn more about this feature, see :ruby:`Query Cache | ||||||||||||
</reference/query-cache/>` in the {+ruby-driver+} documentation. | ||||||||||||
|
||||||||||||
Enable Query Caching | ||||||||||||
-------------------- | ||||||||||||
|
||||||||||||
In this section, you can learn how to enable the query caching feature | ||||||||||||
in your application. You can enable the query cache by using the | ||||||||||||
driver's namespace or {+odm+}'s namespace. | ||||||||||||
|
||||||||||||
Automatic | ||||||||||||
~~~~~~~~~ | ||||||||||||
|
||||||||||||
The {+ruby-driver+} provides middleware to automatically enable the | ||||||||||||
query cache for Rack web requests and Active Job job runs. See the | ||||||||||||
:ref:`Query Cache Rack Middleware <query-cache-middleware>` section of | ||||||||||||
the Configuration guide for instructions. | ||||||||||||
|
query cache for Rack web requests and Active Job job runs. See the | |
:ref:`Query Cache Rack Middleware <query-cache-middleware>` section of | |
the Configuration guide for instructions. | |
query cache for Rack web requests and Active Job job runs. For instructions | |
on automatically enabling the query cache, see the :ref:`Query Cache Rack Middleware <query-cache middleware>` section of the configuration guide. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cache the Result of the first Method | |
Cache the Result of the ``first`` Method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoiding using monospace in titles per style guide
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cached results from ``all``. However, because of the sort that {+odm+} | |
applies to the second call, both methods query the database and | |
cached results from ``all``. However, because {+odm+} applies | |
a sort to the second call, both methods query the database and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: might just be my unfamiliarity with to_a
, but can you briefly explain what this code does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to_a
stores the documents in an array, so when first
applies the sort, its just on the array in memory instead of executing a new query. I can add this info to the page.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,142 @@ | ||||||
.. _mongoid-query-persistence: | ||||||
|
||||||
========================= | ||||||
Persist Data from Queries | ||||||
========================= | ||||||
|
||||||
.. facet:: | ||||||
:name: genre | ||||||
:values: reference | ||||||
|
||||||
.. meta:: | ||||||
:keywords: ruby framework, odm, crud, filter, code example | ||||||
|
||||||
.. contents:: On this page | ||||||
:local: | ||||||
:backlinks: none | ||||||
:depth: 2 | ||||||
:class: singlecol | ||||||
|
||||||
Overview | ||||||
-------- | ||||||
|
||||||
In this guide, you can learn how how to persist data off of your queries | ||||||
in {+odm+}. {+odm+} supports persistence operations off of criteria in a | ||||||
limited capacity, allowing you to to expressively perform multi-document | ||||||
insert, update, and delete operations. | ||||||
|
||||||
To learn more about creating filter criteria, see the | ||||||
:ref:`mongoid-data-specify-query` guide. | ||||||
|
||||||
.. TODO To learn more about performing CRUD operations, see the :ref:`` guide. | ||||||
|
||||||
Persistence Methods | ||||||
------------------- | ||||||
|
||||||
This section describes methods that you can chain to your queries to | ||||||
create, update, and delete data in your MongoDB collections. | ||||||
|
||||||
Create a Document | ||||||
~~~~~~~~~~~~~~~~~ | ||||||
|
||||||
You can use the following methods to create new documents from your | ||||||
query criteria: | ||||||
|
||||||
- ``create``: Saves a model instance to MongoDB | ||||||
|
||||||
- Example: ``Band.where(name: 'Daft Punk').create`` | ||||||
|
||||||
- ``create!``: Saves a model instance to MongoDB or raises an exception | ||||||
if a validation error occurs. | ||||||
|
if a validation error occurs. | |
if a validation error occurs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed periods from all lists except delete section as one entry has two sentences.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s: same suggestion as above.
- ``update``: Updates attributes of the first matching document. | |
- ``update``: Updates attributes of the first matching document |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: up to you, but was wondering why this is a long list instead of a table, given that each method has an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prev got feedback that people think the code in tables is too small to read
Check failure on line 136 in source/interact-data/query-persistence.txt
GitHub Actions / TDBX Vale rules
[vale] reported by reviewdog 🐶
[MongoDB.NegativeWords] Use 'remove, delete' instead of the negative word 'destroy'.
Raw Output:
{"message": "[MongoDB.NegativeWords] Use 'remove, delete' instead of the negative word 'destroy'.", "location": {"path": "source/interact-data/query-persistence.txt", "range": {"start": {"line": 136, "column": 49}}}, "severity": "ERROR"}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: active voice