Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your initial question is about high cpu usage, the answer i think is simple, with GAE and databases like BigTable (non-relational) the code with <code>entries.count()</code> is expensive and the <code>for entry in entrie</code> too if you have a lot of data.</p> <p>I think you must have to do a couple of things:</p> <p>in your <code>utils.py</code></p> <pre><code>def GetDictionaryKey(lang, key): chache_key = 'dictionary_%s_%s' % (lang, key) data = memcache.get(cache_key) if not data: entry = DictionaryEntries.all().filter("lang = ", lang).filter("value =", key).get() if entry: data = memcache.add(cache_key, entry.value, 60) else: data = 'no result for %s' % key return data </code></pre> <p>and in your filter: </p> <pre><code> def translate(key, lang): return dictionary.GetDictionaryKey(lang, key) </code></pre> <p>This approach is better because:</p> <ul> <li>You don't make the expensive query of <code>count</code></li> <li>You respect the MVC pattern, because a filter is part of the Template (View in the pattern) and the method <code>GetDictionaryKey</code> is part of the Controler.</li> </ul> <p>Besides, if you are using django i suggest you slugify your cache_key:</p> <pre><code>from django.template.defaultfilters import slugify def GetDictionaryKey(lang, key): chache_key = 'dictionary_%s_%s' % (slugify(lang), slugify(key)) data = memcache.get(cache_key) if not data: entry = DictionaryEntries.all().filter("lang = ", lang).filter("value =", key).get() if entry: data = memcache.add(cache_key, entry.value, 60) else: data = 'no result for %s' % key return data </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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