Reputation: 1091
I am using Google App Engine free tier with Python and Jinja2 template engine.
My task is to run vote "yes" or "no" on all 5000 items. For that I am using following query on the index page.
{% extends "base.html" %}
{% block content %}
{% for item in items if not item.voted %}
//HTML goes here to display the item
{% break %}
{% endfor %}
{% endblock %}
I am breaking the loop as I want to show just one item anytime on the index page. The item can be randomly chosen, but it must not be voted. That is a very unoptimised/lazy solution which was working just fine locally but on app engine server it's an expensive operation. After voting some items, I get following error:
OverQuotaError: The API call datastore_v3.RunQuery() required more quota than is available.
Can someone suggest any better solution? I have very limited knowledge in using jinja2 template engine so I am unable to find an inexpensive solution.
Upvotes: 1
Views: 77
Reputation: 6278
There are multiple ways to do it.
Add a "random" property you you entity and then do query 1 item (using limit=1) where "RandomProp > randomValue". This is not related to Jinja2 (as Jinja is just a template engine) and should be done in your Python code and consist of 3 parts: modify model to add new prop, when saving entities assign a random value to the new prop, when want to display data do a query with filter on the new property with property greater then some (another) random value.
Keep somewhere list of IDs of the entities and randomly select one and get from DB by key.
Upvotes: 1