Skip to content

Commit

Permalink
Optimization: use _ids in scorelog
Browse files Browse the repository at this point in the history
  • Loading branch information
phlax committed Sep 12, 2016
1 parent 0f6f817 commit 7b5ee6a
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions pootle/apps/pootle_statistics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,18 @@ def get_submission_info(self):
def save(self, *args, **kwargs):
super(Submission, self).save(*args, **kwargs)

if self.needs_scorelog():
for score in ScoreLog.get_scorelogs(submission=self):
if 'action_code' in score and score['user'] is not None:
ScoreLog.objects.create(**score)
if not self.needs_scorelog():
return

scorelogs_created = []
for score in ScoreLog.get_scorelogs(submission=self):
if 'action_code' in score and score['user'] is not None:
if not isinstance(score["user"], models.Model):
score["user_id"] = score["user"]
del score["user"]
scorelogs_created.append(ScoreLog(**score))
if scorelogs_created:
self.scorelog_set.add(*scorelogs_created)


class TranslationActionCodes(object):
Expand Down Expand Up @@ -410,9 +418,9 @@ def get_scorelogs(cls, submission):
'submission': submission,
}

translator = submission.unit.submitted_by
if submission.unit.reviewed_by:
reviewer = submission.unit.reviewed_by
translator = submission.unit.submitted_by_id
if submission.unit.reviewed_by_id:
reviewer = submission.unit.reviewed_by_id
else:
reviewer = translator

Expand Down Expand Up @@ -442,7 +450,7 @@ def get_scorelogs(cls, submission):
TranslationActionCodes.REVIEW_PENALTY
else:
if (reviewer is not None and
submission.submitter.id == reviewer.id):
submission.submitter_id == reviewer):
submitter_score['action_code'] = \
TranslationActionCodes.EDITED_OWN
else:
Expand Down Expand Up @@ -575,7 +583,7 @@ def get_edit_penalty():
# translation was added.
s = Submission.objects.get(
unit__id=self.submission.unit_id,
submitter__id=self.submission.unit.submitted_by_id,
submitter_id=self.submission.unit.submitted_by_id,
creation_time=self.submission.unit.submitted_on,
field=SubmissionFields.TARGET,
type=SubmissionTypes.NORMAL
Expand Down

0 comments on commit 7b5ee6a

Please sign in to comment.