diff options
author | Matthias Hecker <apoc@geekosphere.org> | 2015-07-04 13:51:42 +0200 |
---|---|---|
committer | Matthias Hecker <apoc@geekosphere.org> | 2015-07-04 13:51:42 +0200 |
commit | a2eeb15faadf94c879d749e211d160cb86b659c6 (patch) | |
tree | cee303c895f0f5772de9dcb13943dadff7a12038 | |
parent | c75c3db5b9dd918bb0372d41125993df2fe77374 (diff) |
journal: introduce ensure_payload_index
-rw-r--r-- | lib/rbot/journal.rb | 7 | ||||
-rw-r--r-- | lib/rbot/journal/mongo.rb | 2 | ||||
-rw-r--r-- | test/test_journal.rb | 2 |
3 files changed, 8 insertions, 3 deletions
diff --git a/lib/rbot/journal.rb b/lib/rbot/journal.rb index fe6c14be..981ff6e4 100644 --- a/lib/rbot/journal.rb +++ b/lib/rbot/journal.rb @@ -78,7 +78,6 @@ module Journal def self.create(topic, payload, opt={}) # cleanup payload to only contain strings - payload = payload.map { |k, v| [k.to_s, v.to_s] }.to_h JournalMessage.new( id: opt[:id] || SecureRandom.uuid, timestamp: opt[:timestamp] || Time.now, @@ -99,7 +98,7 @@ module Journal end # creates/ensures a index exists on the payload specified by key - def ensure_index(key) + def ensure_payload_index(key) end # returns a array of message instances that match the query @@ -419,6 +418,10 @@ module Journal @storage.remove(query) end + def ensure_payload_index(key) + @storage.ensure_payload_index(key) + end + end end # Journal diff --git a/lib/rbot/journal/mongo.rb b/lib/rbot/journal/mongo.rb index 2e735587..a03355f9 100644 --- a/lib/rbot/journal/mongo.rb +++ b/lib/rbot/journal/mongo.rb @@ -28,7 +28,7 @@ module Journal @collection.indexes.create_one({timestamp: 1}) end - def ensure_index(key) + def ensure_payload_index(key) @collection.indexes.create_one({'payload.'+key => 1}) end diff --git a/test/test_journal.rb b/test/test_journal.rb index 37497351..f1653c16 100644 --- a/test/test_journal.rb +++ b/test/test_journal.rb @@ -314,6 +314,8 @@ module JournalStorageTestMixin assert_equal(2, msgs.length) assert_equal('bar', msgs.first['message']) assert_equal('baz', msgs.last['message']) + + journal.ensure_payload_index('foo.bar.baz') end NUM=100 # 1_000_000 |