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:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user