]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
journal: introduce ensure_payload_index
authorMatthias Hecker <apoc@geekosphere.org>
Sat, 4 Jul 2015 11:51:42 +0000 (13:51 +0200)
committerMatthias Hecker <apoc@geekosphere.org>
Sat, 4 Jul 2015 11:51:42 +0000 (13:51 +0200)
lib/rbot/journal.rb
lib/rbot/journal/mongo.rb
test/test_journal.rb

index fe6c14be66802c2a93255d0e3c7d7772bcab7c04..981ff6e47eaab41fa496ed929d614615772bd1e8 100644 (file)
@@ -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
index 2e735587acca72aafb25ba0fa3312e470ca3802c..a03355f93e4aea43fabf6f5d12fbe02d30481036 100644 (file)
@@ -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
 
index 374973519300226f9e32f8705124013969d14a48..f1653c164783e35eb3830228aac58531403f337e 100644 (file)
@@ -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