From 57959900bc921b799deceaab82c9eb3458efbe26 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 28 Oct 2015 10:58:12 +0100 Subject: [PATCH 1/3] Small code layout improvement. --- .../controllers/_application_controller_table.coffee | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_application_controller_table.coffee b/app/assets/javascripts/app/controllers/_application_controller_table.coffee index 5e3f5799f..ac3a5d956 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_table.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_table.coffee @@ -355,7 +355,7 @@ class App.ControllerTable extends App.Controller if unit is '%' percentage = parseInt col.width, 10 - col.width = percentage / 100 * @el.width() + "px" + col.width = percentage / 100 * @el.width() + 'px' return col @@ -366,14 +366,14 @@ class App.ControllerTable extends App.Controller headers = _.map headers, (col) => if !col.unresizable value = parseInt col.width, 10 - col.width = Math.max(@minColWidth, value - shrinkBy) + "px" + col.width = Math.max(@minColWidth, value - shrinkBy) + 'px' return col # give left-over space from rounding to last column to get to 100% roundingLeftOver = @el.width() - @getHeaderWidths headers # but only if there is something left over (will get negative when there are too many columns for each column to stay in their min width) if roundingLeftOver > 0 - headers[headers.length - 1].width = parseInt(headers[headers.length - 1].width, 10) + roundingLeftOver + "px" + headers[headers.length - 1].width = parseInt(headers[headers.length - 1].width, 10) + roundingLeftOver + 'px' return headers @@ -383,16 +383,16 @@ class App.ControllerTable extends App.Controller , 0 getHeaderWidths: (headers) -> - widths = _.reduce headers, (memo, col, i) => + widths = _.reduce headers, (memo, col, i) => if col.width value = parseInt col.width, 10 unit = col.width.match(/[px|%]+/)[0] else # !!! sets the width to default width if not set - headers[i].width = @baseColWidth+'px' + headers[i].width = @baseColWidth + 'px' value = @baseColWidth unit = 'px' - + return if unit is 'px' then memo + value else memo , 0 From 0707bfa51238de3568de150a5ac96ee50804f536 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 28 Oct 2015 13:24:52 +0100 Subject: [PATCH 2/3] Increased speed of Translation.load, just update if needed. --- app/models/translation.rb | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/app/models/translation.rb b/app/models/translation.rb index 41ca2718a..51d820ef3 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -45,23 +45,32 @@ dedicated: fail "Can't load translations from #{url}: #{result.error}" if !result.success? ActiveRecord::Base.transaction do - result.data.each {|translation| + result.data.each {|translation_raw| # handle case insensitive sql - exists = Translation.where(locale: translation['locale'], format: translation['format'], source: translation['source']) - translaten = nil + exists = Translation.where(locale: translation_raw['locale'], format: translation_raw['format'], source: translation_raw['source']) + translation = nil exists.each {|item| - if item.source == translation['source'] - translaten = item + if item.source == translation_raw['source'] + translation = item end } - if translaten + if translation # verify if update is needed - translaten.update_attributes(translation.symbolize_keys!) - translaten.save + update_needed = false + translation_raw.each {|key, _value| + if translation_raw[key] == translation[key] + update_needed = true + break + end + } + if update_needed + translation.update_attributes(translation_raw.symbolize_keys!) + translation.save + end else - Translation.create(translation.symbolize_keys!) + Translation.create(translation_raw.symbolize_keys!) end } end From f0431d584ae9c912fba583a096a35960dbd1c5f1 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 28 Oct 2015 13:26:41 +0100 Subject: [PATCH 3/3] Increased speed of Translation.load, just update if needed. --- app/models/translation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/translation.rb b/app/models/translation.rb index 51d820ef3..78c302bc7 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -60,7 +60,7 @@ dedicated: # verify if update is needed update_needed = false translation_raw.each {|key, _value| - if translation_raw[key] == translation[key] + if translation_raw[key] != translation[key] update_needed = true break end