Skip to content

Commit 9d932d4

Browse files
author
Sam Kleinman
committed
DOCS-169 edits and feedback from mikeo
1 parent 61b048d commit 9d932d4

File tree

4 files changed

+38
-23
lines changed

4 files changed

+38
-23
lines changed

aspiration/use-cases/cms-metadata-and-asset-management.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ The most common operations inside of a CMS center on creating and
153153
editing content. Consider the following :py:meth:`<pymongo:pymongo.collection.Collection.insert>`
154154
operation:
155155

156-
TODO figure out what role the nonce plays. mikeo
157-
158156
.. code-block:: python
159157

160158
db.cms.nodes.insert({
@@ -174,9 +172,11 @@ TODO figure out what role the nonce plays. mikeo
174172
})
175173

176174
Once inserted, your application must have some way of preventing
177-
multiple concurrent updates. The schema uses the special
178-
``nonce`` field which makes it possible for the application to detect
179-
concurrent edits. Consider the following :py:meth:`update <pymongo:pymongo.collection.Collection.update>`
175+
multiple concurrent updates. The schema uses the special ``nonce``
176+
field to help detect concurrent edits. By using the ``nonce`` field in
177+
the query portion of the :py:meth:`update <pymongo:pymongo.collection.Collection.update>`
178+
operation, the application will generate an error if there is an
179+
editing collision. Consider the following :py:meth:`update <pymongo:pymongo.collection.Collection.update>`
180180

181181
.. code-block:: python
182182

aspiration/use-cases/cms-storing-comments.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ structure like the following:
9999
text: 'This is so bogus ... '
100100
}
101101

102-
TODO changed full_slug order; talk to mikeo
103-
104102
This structure:
105103

106104
- adds a ``parent_id`` field that stores the contents of the ``_id``
@@ -113,6 +111,13 @@ This structure:
113111
information to make it easier to sort documents in a threaded
114112
discussion by date.
115113

114+
.. warning::
115+
116+
MongoDB can only index :ref:`128 characters <limits-index-size>`
117+
including field name and namespace (i.e. database name and
118+
collection name.) This may become an issue when you create an index
119+
of the ``full_slug`` field to support sorting.
120+
116121
Operations
117122
~~~~~~~~~~
118123

aspiration/use-cases/ecommerce-inventory-management.txt

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,6 @@ cleanup operation that finds inventory items that have ``carted``
355355
items and check that to ensure that they exist in a user's cart, and
356356
return them to available inventory if they do not.
357357

358-
TODO talk to mikeo
359-
360358
.. code-block:: python
361359

362360
def cleanup_inventory(timeout):
@@ -372,7 +370,7 @@ TODO talk to mikeo
372370
for carted_item in item['carted']
373371
if carted_item['timestamp'] < threshold)
374372

375-
# Find any carts that are active and refresh the carted items
373+
# First Pass: Find any carts that are active and refresh the carted items
376374
for cart in db.cart.find({ '_id': {'$in': carted.keys() }, 'status':'active'}):
377375
cart = carted[cart['_id']]
378376

@@ -382,7 +380,7 @@ TODO talk to mikeo
382380
{ '$set': {'carted.$.timestamp': now } })
383381
del carted[cart['_id']]
384382

385-
# All the carted items left in the dict need to now be
383+
# Second Pass: All the carted items left in the dict need to now be
386384
# returned to inventory
387385
for cart_id, carted_item in carted.items():
388386
db.inventory.update(
@@ -392,6 +390,18 @@ TODO talk to mikeo
392390
{ '$inc': { 'qty': carted_item['qty'] },
393391
'$pull': { 'carted': { 'cart_id': cart_id } } })
394392

393+
TODO edit and polish the next paragraph.
394+
395+
To summarize: This operation finds all "carted" items that have
396+
time stamps older than the threshold. Then, the process makes two
397+
passes over these items:
398+
399+
#. Of the items with time stamps older than the threshold, if the cart
400+
is still active, it resets the time stamp to maintain the carts.
401+
402+
#. Of the stale items that remain in inactive carts, the operation
403+
returns these items to the inventory.
404+
395405
.. note::
396406

397407
The function above is safe for use because it checks to ensure that
@@ -417,9 +427,19 @@ There are two drawbacks for using ``_id`` as a shard key:
417427

418428
You can mitigate this effect by choosing a random value upon the
419429
creation of a cart, such as a hash (i.e. MD5 or SHA-1) of an
420-
ObjectID, as the ``_id``.
430+
ObjectID, as the ``_id``. The process for this operation would
431+
resemble the following:
432+
433+
.. code-block:: python
434+
435+
import hashlib
436+
import bson
437+
438+
cart_id = bson.ObjectId()
439+
cart_id_hash = hashlib.md5(str(cart_id)).hexdigest()
421440

422-
TODO insert code example for creating a hashed key in python. mikeo
441+
cart = { "_id": cart_id, "cart_hash": cart_id_hash }
442+
db.cart.insert(cart)
423443

424444
- Cart expiration and inventory adjustment requires update operations
425445
and queries to broadcast to all shards when using ``_id`` as a shard

aspiration/use-cases/real-time-analytics-pre-aggregated-reports.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,6 @@ over the last day, with hour-level granularity:
474474
If you want a few days of hourly data, you can use a query in the
475475
following form:
476476

477-
TODO talk to mikeo
478-
479477
.. code-block:: pycon
480478

481479
>>> db.stats.daily.find(
@@ -486,14 +484,6 @@ TODO talk to mikeo
486484
... { 'metadata.date': 1, 'hourly': 1 } },
487485
... sort=[('metadata.date', 1)])
488486

489-
This query allows you to retrieve the date along with the data to
490-
protect the unlikely situation where you have a day where:
491-
492-
- your application did not pre-allocate a document for that resource,
493-
and
494-
495-
- the resource in question receive no events, or requests.
496-
497487
Indexing
498488
````````
499489

0 commit comments

Comments
 (0)