-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Js translations #147
base: master
Are you sure you want to change the base?
Js translations #147
Changes from all commits
4b4468c
e9cb985
aad3a6d
c47427a
eaae4d5
3aaed71
c7d87ef
6bf7b88
a9db5d6
756c801
3efd01f
5cf8334
4e2615e
87c5b1c
e2582a9
14968cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Lit | ||
if defined?(::ActiveJob) | ||
class PersitGlobalHitsCountersJob < ::ActiveJob::Base | ||
queue_as :default | ||
|
||
def perform(update_array) | ||
PersitGlobalHitsCountersService.new(update_array).execute | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,12 @@ | ||||||
class PersitGlobalHitsCountersService | ||||||
def initialize(update_array) | ||||||
@update_array = update_array | ||||||
end | ||||||
|
||||||
def execute | ||||||
@update_array.each do |a| | ||||||
Lit::LocalizationKey.find(a[0]).update_columns(usage_count: a[1], used_last_at: Time.now) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as per my comment to
Suggested change
|
||||||
end | ||||||
end | ||||||
|
||||||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<h3><%= I18n.t('lit.not_used_header', default: 'Not used localization keys') %></h3> | ||
|
||
<%= render 'localizations_list', available_locales: I18n.backend.available_locales %> | ||
|
||
<% if defined?(Kaminari) %> | ||
<%= paginate @localization_keys, :theme=>"lit" %> | ||
<% elsif defined?(WillPaginate) %> | ||
<%= will_paginate @localization_keys %> | ||
<% end %> | ||
|
||
<%= render 'sidebar' %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<h3><%= I18n.t('lit.used_header', default: 'Used localization keys') %></h3> | ||
|
||
<%= render 'localizations_list', available_locales: I18n.backend.available_locales %> | ||
|
||
<% if defined?(Kaminari) %> | ||
<%= paginate @localization_keys, :theme=>"lit" %> | ||
<% elsif defined?(WillPaginate) %> | ||
<%= will_paginate @localization_keys %> | ||
<% end %> | ||
|
||
<%= render 'sidebar' %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class LitAddUsageCountAndUsedLastAtToLitLocalizationKeys < Rails::VERSION::MAJOR >= 5 ? | ||
ActiveRecord::Migration[4.2] : | ||
ActiveRecord::Migration | ||
def change | ||
add_column :lit_localization_keys, :usage_count, :integer, index: true | ||
add_column :lit_localization_keys, :used_last_at, :datetime, index: true | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ module Lit | |
class Cache | ||
def initialize | ||
@hits_counter = Lit.get_key_value_engine | ||
@hits = 0 | ||
@request_info_store = Lit.get_key_value_engine | ||
@hits_counter_working = true | ||
@keys = nil | ||
|
@@ -143,6 +144,18 @@ def get_global_hits_counter(key) | |
@hits_counter['global_hits_counter.' + key] | ||
end | ||
|
||
def persit_global_hits_counters | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Over time this will grow - I suggest clearing that with every call of |
||
update_array = [] | ||
@hits_counter.each do |k,v| | ||
if k.match?(/^global_hits_counter/) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be works considering adding new method to Redis and Hash adapter, that will return all keys matching given criteria, ie. redis has this already built in: https://redis.io/commands/keys |
||
localization_key = find_localization_key(k.gsub("global_hits_counter.", "")) | ||
update_array << [localization_key.id, @hits_counter[k] + localization_key.usage_count.to_i] | ||
#localization_key.update_columns(usage_count: @hits_counter[k] + localization_key.usage_count.to_i, used_last_at: Time.now) | ||
end | ||
end | ||
PersitGlobalHitsCountersJob.perform_later(update_array) | ||
end | ||
|
||
def get_hits_counter(key) | ||
@hits_counter['hits_counter.' + key] | ||
end | ||
|
@@ -310,6 +323,8 @@ def find_or_create_localization_key(key_without_locale) | |
def update_hits_count(key) | ||
return unless @hits_counter_working | ||
key_without_locale = split_key(key).last | ||
@hits += 1 | ||
persit_global_hits_counters if Lit.persit_global_hits_count.present? && (@hits%Lit.persit_global_hits_count) == 0 | ||
@hits_counter.incr('hits_counter.' + key) | ||
@hits_counter.incr('global_hits_counter.' + key_without_locale) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revert that