[Groonga-commit] droonga/fluent-plugin-droonga at 8a73d76 [master] Implement watch method

Back to archive index

Yoji Shidara null+****@clear*****
Fri Oct 11 14:51:20 JST 2013


Yoji Shidara	2013-10-11 14:51:20 +0900 (Fri, 11 Oct 2013)

  New Revision: 8a73d76176cfeeaf460dee4ff2ca799f9d7358db
  https://github.com/droonga/fluent-plugin-droonga/commit/8a73d76176cfeeaf460dee4ff2ca799f9d7358db

  Message:
    Implement watch method

  Modified files:
    lib/droonga/plugin/handler_watch.rb

  Modified: lib/droonga/plugin/handler_watch.rb (+35 -2)
===================================================================
--- lib/droonga/plugin/handler_watch.rb    2013-10-11 14:48:15 +0900 (c9d2c8d)
+++ lib/droonga/plugin/handler_watch.rb    2013-10-11 14:51:20 +0900 (8c85d2c)
@@ -23,8 +23,27 @@ module Droonga
 
     command "watch"
     def watch(request)
-      p parse_request(request)
-      # TODO
+      user, condition, query, route = parse_request(request)
+      query_table = @context['Query']
+      query_record = query_table[query]
+      unless query_record
+        keywords = pick_keywords([], condition)
+        query_record = query_table.add(query, :keywords => keywords)
+      end
+      user_table = @context['User']
+      user_record = user_table[user]
+      if user_record
+        subscriptions = user_record.subscriptions.collect do |query|
+          return if query == query_record
+          query
+        end
+        subscriptions << query_record
+        user_record.subscriptions = subscriptions
+      else
+        user_table.add(user,
+                       :subscriptions => [query_record],
+                       :route => route)
+      end
     end
 
     private
@@ -37,5 +56,19 @@ module Droonga
       raise "too long query" if query.size > 4095
       [user, condition, query, route]
     end
+
+    def pick_keywords(memo, condition)
+      case condition
+      when Hash
+        memo << condition["query"]
+      when String
+        memo << condition
+      when Array
+        condition[1..-1].each do |element|
+          pick_keywords(memo, element)
+        end
+      end
+      memo
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index