From 47714f7042cf268ea420bf3c6b777836641bda57 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 18 Nov 2015 08:37:18 +0100 Subject: [PATCH] Speedup of syncing translations. --- app/models/translation.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/models/translation.rb b/app/models/translation.rb index 78c302bc7..dadee9ed4 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -44,16 +44,17 @@ dedicated: ) fail "Can't load translations from #{url}: #{result.error}" if !result.success? + translations = Translation.where(locale: locale).all ActiveRecord::Base.transaction do result.data.each {|translation_raw| # handle case insensitive sql - exists = Translation.where(locale: translation_raw['locale'], format: translation_raw['format'], source: translation_raw['source']) translation = nil - exists.each {|item| - if item.source == translation_raw['source'] - translation = item - end + translations.each {|item| + next if item.format != translation_raw['format'] + next if item.source != translation_raw['source'] + translation = item + break } if translation