Skip to content

Commit

Permalink
Only write changes back out if something changed
Browse files Browse the repository at this point in the history
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 bc5f451
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions experiments/utils.py
Expand Up @@ -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
Expand Down

0 comments on commit bc5f451

Please sign in to comment.