1
0
mirror of https://github.com/projekteuler/projekteuler.git synced 2026-01-27 02:28:50 +01:00

Prevent N+1 on title validation

This commit is contained in:
2015-02-12 18:26:02 +01:00
parent c124808ffe
commit b1d0daf47a

View File

@@ -7,7 +7,7 @@ class Translation < ActiveRecord::Base
self.per_page = 50 self.per_page = 50
def title_is_unique_among_other_problems def title_is_unique_among_other_problems
Problem.where.not(id: problem_id).each do |problem| Problem.includes(:translation).where.not(id: problem_id).each do |problem|
if problem.is_translated? and problem.title == title if problem.is_translated? and problem.title == title
errors.add(:title, :taken) errors.add(:title, :taken)
break break