Permalink
Browse files

Added an optimization for db.put since large number of model entities…

… will throw exceptions.
  • Loading branch information...
1 parent e72ba27 commit 53e48677ee4c4d786f581699cb00521f50f4ef13 @ibolmo committed May 30, 2009
Showing with 36 additions and 27 deletions.
  1. +1 −1 app.yaml
  2. +0 −14 index.yaml
  3. +25 −6 measure.py
  4. +2 −0 myapp/stat.py
  5. +1 −1 myapp/templates/campaign_detail.html
  6. +1 −1 myapp/templates/campaign_form.html
  7. +1 −1 myapp/templates/campaign_list.html
  8. +3 −3 myapp/views.py
  9. +2 −0 settings.py
View
@@ -1,5 +1,5 @@
application: cametrics
-version: 2
+version: 1
runtime: python
api_version: 1
View
@@ -1,17 +1,3 @@
-indexes:
-
-- kind: django_admin_log
- properties:
- - name: content_type
- - name: object_id
- - name: action_time
-
-- kind: django_admin_log
- properties:
- - name: user
- - name: action_time
- direction: desc
-
# AUTOGENERATED
# This index.yaml is automatically updated whenever the dev_appserver
View
@@ -53,19 +53,36 @@ def post(self, key, path, format):
models.append(create_datum(self.campaign, path, self.request))
models += _Stats.values() + stat._Hists.values()
+ send_to_datastore(models)
+ self.response.set_status(error and 304 or 201)
+
+def send_to_datastore(models):
+ lm = len(models)
+ first, second = (models[:lm / 2], models[lm / 2:])
+ if first:
try:
- keys = db.put(models)
+ lf = len(first)
+ logging.debug('Saving first: %s/%s' % (lf, lm))
+ db.put(first)
+ logging.info('::STATS:: db.put(%s)' % lf)
except:
- error = True
- logging.warning('Could not save all models')
- self.response.set_status(error and 304 or 201)
+ logging.warning('Could not save first set')
+ send_to_datastore(first)
+
+ if second:
+ try:
+ ls = len(second)
+ logging.debug('Saving second: %s/%s' % (ls, lm))
+ db.put(second)
+ logging.info('::STATS:: db.put(%s)' % ls)
+ except:
+ logging.warning('Could not save second set')
+ send_to_datastore(second)
def create_datum(campaign, ns, obj = {}):
ns = ns.strip('/').replace('/', '.')
value = obj.get('value')
kind = obj.get('type', 'number')
-
- logging.debug('POST | value: %s | kind: %s' % (value, kind))
datum = Storage(campaign = campaign, namespace = ns, type = kind, value = value)
@@ -80,6 +97,8 @@ def create_datum(campaign, ns, obj = {}):
if not hasattr(datum, '_invalid'):
helper.calculate(datum)
return datum
+ else:
+ logging.warning('datum invalid %s/%s, %s, %s' % (campaign, ns, datum.value, datum.type))
def cleanup_relations(sender, **kwargs):
campaign = kwargs.get('instance')
View
@@ -9,6 +9,8 @@ def get(prop):
for Class in Summaries:
if hasattr(Class, 'match_type') and Class.match_type and prop in Class.match_type:
return Class
+
+ logging.debug('No Summary for %s' % prop)
return NoSummary
class NoSummary(object):
@@ -3,7 +3,7 @@
{% block content %}
<h2>Campaign Details</h2>
-<a href="{% url myapp.views.list_campaigns %}">Back to listing</a> | <a href="{% url myapp.views.edit_campaign key=object.key %}">Edit</a> | <a href="{% url myapp.views.delete_campaign key=object.key %}">Delete</a>
+<a href="{% url myapp.views.list_campaigns %}">Back to listing</a> | <a href="{% url myapp.views.edit_campaign key=object.key %}">Edit</a>
<hr class="space" />
<h3>{{ object.title }}</h3>
@@ -7,7 +7,7 @@
<form action="" method="post" enctype="multipart/form-data">
<table>
- {{ form.as_table }}
+ {{ form }}
<tr><td colspan="2">
<input type="submit"
value="{% if object %}Apply changes{% else %}Create{% endif %}" />
@@ -11,7 +11,7 @@
<ul>
{% for campaign in object_list %}
<li>
- [<a href="{% url myapp.views.edit_campaign key=campaign.key %}">Edit</a> | <a href="{% url myapp.views.delete_campaign key=campaign.key %}">Delete</a>] <a href="{% url myapp.views.show_campaign key=campaign.key %}">{{ campaign.title }}</a>, {{ campaign.description }}
+ [<a href="{% url myapp.views.edit_campaign key=campaign.key %}">Edit</a>] <a href="{% url myapp.views.show_campaign key=campaign.key %}">{{ campaign.title }}</a>, {{ campaign.description }}
</li>
{% endfor %}
</ul>
View
@@ -6,14 +6,14 @@
from ragendja.template import render_to_response
import logging, renderer
-from myapp.forms import CampaignForm
+from forms import CampaignForm
from models import Campaign, TaskModel
from django.contrib.auth.decorators import login_required
@login_required
def list_campaigns(request):
- return object_list(request, Campaign.all().filter('organizer =', request.user.key()), paginate_by = 10, template_name = 'campaign_list.html')
+ return object_list(request, Campaign.all().filter('organizer =', request.user), paginate_by = 10, template_name = 'campaign_list.html')
@login_required
def show_campaign(request, key):
@@ -30,7 +30,7 @@ def add_campaign(request):
return redirect(reverse('myapp.views.show_campaign', kwargs = dict(key = '%(key)s')), campaign)
else:
form = CampaignForm()
- return render_to_response(request, 'myapp/campaign_form.html', {'form': form})
+ return render_to_response(request, 'campaign_form.html', {'form': form})
@login_required
def edit_campaign(request, key):
View
@@ -1,5 +1,7 @@
from ragendja.settings_pre import *
+DEBUG = True
+
DJANGO_STYLE_MODEL_KIND = False
import config

0 comments on commit 53e4867

Please sign in to comment.