Permalink
Browse files

Only write changes back out if something changed

Adding a goal does one database update per enrollment the user is in,
this way at least these writes are only done if the contents has
actually changed.
  • Loading branch information...
theospears committed Oct 4, 2012
1 parent b530e80 commit bc5f451510721fe534fcc2c4f0068e33341211b2
Showing with 2 additions and 7 deletions.
  1. +2 −7 experiments/utils.py
View
@@ -180,24 +180,19 @@ def record_goal(self, goal_name):
if self.should_increment(enrollment.experiment, enrollment.goals, goal_name):
self.increment_goal_count(enrollment.experiment, enrollment.alternative, goal_name)
enrollment.goals.append(goal_name)
- new_goals = enrollment.goals
- enrollment.goals = new_goals
- enrollment.save()
+ enrollment.save()
return
# If confirmed human
if self.is_verified_human():
enrollments = self.session.get('experiments_enrollments', None)
- new_enrollments = enrollments
if not enrollments:
return
for experiment_name, (alternative, goals) in enrollments.items():
if self.should_increment(experiment_manager[experiment_name], goals, goal_name):
self.increment_goal_count(experiment_manager[experiment_name], alternative, goal_name)
goals.append(goal_name)
- new_goals = goals
- new_enrollments[experiment_name] = (alternative, new_goals)
- self.session['experiments_enrollments'] = new_enrollments
+ self.session['experiments_enrollments'] = enrollments
return
else:
# TODO: store temp goals and convert later when is_human is triggered

0 comments on commit bc5f451

Please sign in to comment.