From 6211ffb416592782bc8103ab29d63189623b187c Mon Sep 17 00:00:00 2001 From: Matthias H Date: Thu, 6 Mar 2014 14:20:27 +0100 Subject: [registry] small refactoring and added flush test --- lib/rbot/registry/daybreak.rb | 5 +++++ lib/rbot/registry/dbm.rb | 11 ----------- lib/rbot/registry/sqlite.rb | 5 ++--- lib/rbot/registry/tc.rb | 5 +++++ 4 files changed, 12 insertions(+), 14 deletions(-) (limited to 'lib/rbot/registry') diff --git a/lib/rbot/registry/daybreak.rb b/lib/rbot/registry/daybreak.rb index 6058b408..233c3a0d 100644 --- a/lib/rbot/registry/daybreak.rb +++ b/lib/rbot/registry/daybreak.rb @@ -24,6 +24,11 @@ class Registry @registry ||= Daybreak::DB.new(@filename) end + def flush + return unless @registry + @registry.flush + end + def optimize return unless @registry @registry.compact diff --git a/lib/rbot/registry/dbm.rb b/lib/rbot/registry/dbm.rb index a13cb8ce..9c0304a9 100644 --- a/lib/rbot/registry/dbm.rb +++ b/lib/rbot/registry/dbm.rb @@ -23,21 +23,10 @@ class Registry @registry ||= DBM.open(@filename, 0666, DBM::WRCREAT) end - def flush - return if !@registry - # ruby dbm has no flush, so we close/reopen :( - close - registry - end - def dbexists? not Dir.glob(@filename + '.*').empty? end - def optimize - # unsupported! - end - end end # Registry diff --git a/lib/rbot/registry/sqlite.rb b/lib/rbot/registry/sqlite.rb index 89e7d78c..1af5d242 100644 --- a/lib/rbot/registry/sqlite.rb +++ b/lib/rbot/registry/sqlite.rb @@ -29,10 +29,9 @@ class Registry @registry end - def flush - end - def optimize + return unless @registry + @registry.execute('VACUUM') end def [](key) diff --git a/lib/rbot/registry/tc.rb b/lib/rbot/registry/tc.rb index 63bfdf78..4e248f42 100644 --- a/lib/rbot/registry/tc.rb +++ b/lib/rbot/registry/tc.rb @@ -36,6 +36,11 @@ class Registry @registry.sync end + def optimize + return unless @registry + @registry.optimize + end + end end # Registry -- cgit v1.2.3