mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
translation accelerator
This commit is contained in:
parent
4d9dc82be0
commit
737bb96737
1 changed files with 27 additions and 0 deletions
27
lib/freedom_patches/translate_accelerator.rb
Normal file
27
lib/freedom_patches/translate_accelerator.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
module I18n
|
||||
# this accelerates translation a tiny bit (halves the time it takes)
|
||||
class << self
|
||||
alias_method :translate_no_cache, :translate
|
||||
alias_method :reload_no_cache!, :reload!
|
||||
LRU_CACHE_SIZE = 2000
|
||||
|
||||
def reload!
|
||||
@cache = nil
|
||||
reload_no_cache!
|
||||
end
|
||||
|
||||
def translate(*args)
|
||||
@cache ||= LruRedux::ThreadSafeCache.new(LRU_CACHE_SIZE)
|
||||
found = true
|
||||
k = [args,config.locale,config.backend.object_id]
|
||||
t = @cache.fetch(k){found=false}
|
||||
unless found
|
||||
t = @cache[k] = translate_no_cache(*args)
|
||||
end
|
||||
|
||||
t
|
||||
end
|
||||
|
||||
alias_method :t, :translate
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue