Module: Regurgitator::Domain
Overview
helpers for domain lookups
Instance Method Summary collapse
-
#domain_init ⇒ Object
:nodoc:.
-
#get_dmid(domain) ⇒ Object
returns the
dmid
(domain identifier/primary key) for a stringdomain
. -
#refresh_domain ⇒ Object
We cache the list of all available domains in memory, this shouldn’t be too huge, though…
-
#refresh_domain_unlocked ⇒ Object
:nodoc:.
Instance Method Details
#domain_init ⇒ Object
:nodoc:
5 6 7 8 9 |
# File 'lib/regurgitator/domain.rb', line 5 def domain_init @domain_lock = Mutex.new @domain_cache_mtime = 0 @domain_cache = nil end |
#get_dmid(domain) ⇒ Object
returns the dmid
(domain identifier/primary key) for a string domain
12 13 14 |
# File 'lib/regurgitator/domain.rb', line 12 def get_dmid(domain) refresh_domain[domain] || false end |
#refresh_domain ⇒ Object
We cache the list of all available domains in memory, this shouldn’t be too huge, though…
Returns a hash with string namespaces as keys and dmids as values
20 21 22 |
# File 'lib/regurgitator/domain.rb', line 20 def refresh_domain # :nodoc: @domain_lock.synchronize { refresh_domain_unlocked } end |
#refresh_domain_unlocked ⇒ Object
:nodoc:
24 25 26 27 28 29 30 31 32 |
# File 'lib/regurgitator/domain.rb', line 24 def refresh_domain_unlocked # :nodoc: return @domain_cache if ((Regurgitator.now - @domain_cache_mtime) < 15) tmp = {} @db['SELECT dmid,namespace FROM domain'.freeze].each do |x| tmp[x[:namespace].freeze] = x[:dmid] end @domain_cache_mtime = Regurgitator.now @domain_cache = tmp end |