Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I agree that <code>ComputedProperty</code> is the way to go for the specific scenario described. However, it could still be useful to overload the <code>put</code> function. For instance, we employ the following code to keep track of all of the callers who are issuing datastore writes so that we can easily debug spikes in writes.</p> <pre><code>from google.appengine.ext import db _orig_db_put_async = db.put_async _orig_db_model_put = db.Model.put def _new_db_put_async(models, *args, **kwargs): """Instrumented version of db.put_async (which db.put also calls).""" retval = _orig_db_put_async(models, *args, **kwargs) msg = ['query: %s' % _get_caller()] # 'models' can be either a single model instance, or a list of them. try: for model in models: msg.append(model.__class__.__name__ + '.&lt;db.put&gt;') except TypeError: msg.append(models.__class__.__name__ + '.&lt;db.put&gt;') instance_cache.increment(' -- '.join(msg)) return retval def _new_db_model_put(self, *args, **kwargs): """Like entity.put() but stores put-stats in the instance cache.""" retval = _orig_db_model_put(self, *args, **kwargs) msg = ['query: %s' % _get_caller()] msg.append(self.__class__.__name__ + '.&lt;put&gt;') instance_cache.increment(' -- '.join(msg)) return retval </code></pre> <p>This code keeps a count of which codepaths are issuing writes in memcache and then occasionally flushes it out to the logs. The log lines look something like this:</p> <p><code>3041: activity_summary.py:312 -- UserData.&lt;put&gt;</code></p> <p>Where <code>3041</code> is the number of times line <code>312</code> of activity_summary.py issued a <code>UserData.put()</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload