]> granicus.if.org Git - ejabberd/commitdiff
PubSub: Cleanup tree requests, rename pubsub_node.type->pubsub_node.plugin
authorChristophe Romain <christophe.romain@process-one.net>
Thu, 16 Nov 2017 10:38:04 +0000 (11:38 +0100)
committerChristophe Romain <christophe.romain@process-one.net>
Thu, 16 Nov 2017 10:38:04 +0000 (11:38 +0100)
sql/lite.sql
sql/mssql.sql
sql/mysql.sql
sql/pg.new.sql
sql/pg.sql
src/node_flat_sql.erl
src/node_pep_sql.erl
src/nodetree_tree_sql.erl

index b0c8675f53993f584c045e3519bbf541a9ffa171..e9d2ac6f2dcbd87bf294e495820af6feda5baae6 100644 (file)
@@ -203,7 +203,7 @@ CREATE TABLE pubsub_node (
   host text NOT NULL,
   node text NOT NULL,
   parent text NOT NULL DEFAULT '',
-  type text NOT NULL,
+  plugin text NOT NULL,
   nodeid INTEGER PRIMARY KEY AUTOINCREMENT
 );
 CREATE INDEX i_pubsub_node_parent ON pubsub_node (parent);
index 83b2192988419a05e1a67d4265c6f8a1b80de6c0..8a24bd5d506bf815f4c5ef39091f0f6daad46961 100644 (file)
@@ -279,7 +279,7 @@ CREATE TABLE [dbo].[pubsub_node] (
         [host] [varchar] (255) NOT NULL,\r
         [node] [varchar] (255) NOT NULL,\r
         [parent] [varchar] (255) NOT NULL DEFAULT '',\r
-        [type] [text] NOT NULL,\r
+        [plugin] [text] NOT NULL,\r
         [nodeid] [bigint] IDENTITY(1,1) NOT NULL,\r
  CONSTRAINT [pubsub_node_PRIMARY] PRIMARY KEY CLUSTERED \r
 (\r
index acf2bfe1a43bc17b8f221b4d4966bc185b348806..3e34bbb32de3b31d37a6068e6ce3974915ba9a96 100644 (file)
@@ -215,7 +215,7 @@ CREATE TABLE pubsub_node (
   host text NOT NULL,
   node text NOT NULL,
   parent VARCHAR(191) NOT NULL DEFAULT '',
-  type text NOT NULL,
+  plugin text NOT NULL,
   nodeid bigint auto_increment primary key
 ) ENGINE=InnoDB CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
 CREATE INDEX i_pubsub_node_parent ON pubsub_node(parent(120));
index b155a4223fa013042a5f850b9b1f7c39ece135e0..feb33477901857c1d63a8f766192fbc1ba37bec5 100644 (file)
@@ -396,7 +396,7 @@ CREATE TABLE pubsub_node (
   host text NOT NULL,
   node text NOT NULL,
   parent text NOT NULL DEFAULT '',
-  "type" text NOT NULL,
+  plugin text NOT NULL,
   nodeid SERIAL UNIQUE
 );
 CREATE INDEX i_pubsub_node_parent ON pubsub_node USING btree (parent);
index fd56ba39d2aaf734446ccb81c7a1f69e13b10a64..48f4a85d4fb44392251c3090c3240d7daff81366 100644 (file)
@@ -221,7 +221,7 @@ CREATE TABLE pubsub_node (
   host text NOT NULL,
   node text NOT NULL,
   parent text NOT NULL DEFAULT '',
-  "type" text NOT NULL,
+  plugin text NOT NULL,
   nodeid SERIAL UNIQUE
 );
 CREATE INDEX i_pubsub_node_parent ON pubsub_node USING btree (parent);
index 5995d9fa3a198361317333fd81a04ab99388f86f..afbc050a8f3f4738b09292502b5d828ea9b9ca63 100644 (file)
@@ -337,7 +337,7 @@ get_entity_affiliations(Host, Owner) ->
     J = encode_jid(GenKey),
     {result,
      case ejabberd_sql:sql_query_t(
-           ?SQL("select @(node)s, @(type)s, @(i.nodeid)d, @(affiliation)s "
+           ?SQL("select @(node)s, @(plugin)s, @(i.nodeid)d, @(affiliation)s "
                 "from pubsub_state i, pubsub_node n where "
                 "i.nodeid = n.nodeid and jid=%(J)s and host=%(H)s")) of
         {selected, RItems} ->
@@ -389,13 +389,13 @@ get_entity_subscriptions(Host, Owner) ->
     Query = case SubKey of
              GenKey ->
                GJLike = <<(encode_jid_like(GenKey))/binary, "/%">>,
-               ?SQL("select @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+               ?SQL("select @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
                     "from pubsub_state i, pubsub_node n "
                     "where i.nodeid = n.nodeid and "
                     "(jid=%(GJ)s or jid like %(GJLike)s escape '^') and host=%(H)s");
              _ ->
                SJ = encode_jid(SubKey),
-               ?SQL("select @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+               ?SQL("select @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
                     "from pubsub_state i, pubsub_node n "
                     "where i.nodeid = n.nodeid and "
                     "jid in (%(SJ)s, %(GJ)s) and host=%(H)s")
@@ -431,14 +431,14 @@ get_entity_subscriptions_for_send_last(Host, Owner) ->
     Query = case SubKey of
              GenKey ->
                GJLike = <<(encode_jid_like(GenKey))/binary, "/%">>,
-               ?SQL("select @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+               ?SQL("select @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
                     "from pubsub_state i, pubsub_node n, pubsub_node_option o "
                     "where i.nodeid = n.nodeid and n.nodeid = o.nodeid and "
                     "name='send_last_published_item' and val='on_sub_and_presence' and "
                     "(jid=%(GJ)s or jid like %(GJLike)s escape '^') and host=%(H)s");
              _ ->
                SJ = encode_jid(SubKey),
-               ?SQL("select @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+               ?SQL("select @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
                     "from pubsub_state i, pubsub_node n, pubsub_node_option o "
                     "where i.nodeid = n.nodeid and n.nodeid = o.nodeid and "
                     "name='send_last_published_item' and val='on_sub_and_presence' and "
index 07ff24b51ee429df7c721665f0e078e64758ba82..4a2690c27fa295f1283afd69a97a7fec5f1cc62c 100644 (file)
@@ -123,13 +123,13 @@ get_entity_subscriptions(_Host, Owner) ->
     Query = case SubKey of
              GenKey ->
                GJLike = <<(node_flat_sql:encode_jid_like(GenKey))/binary, "/%">>,
-               ?SQL("select @(host)s, @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+               ?SQL("select @(host)s, @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
                     "from pubsub_state i, pubsub_node n "
                     "where i.nodeid = n.nodeid and "
                     "(jid=%(GJ)s or jid like %(GJLike)s escape '^') and host like %(HLike)s escape '^'");
              _ ->
                SJ = node_flat_sql:encode_jid(SubKey),
-               ?SQL("select @(host)s, @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+               ?SQL("select @(host)s, @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
                     "from pubsub_state i, pubsub_node n "
                     "where i.nodeid = n.nodeid and "
                     "jid in (%(SJ)s,%(GJ)s) and host like %(HLike)s escape '^'")
@@ -159,14 +159,14 @@ get_entity_subscriptions_for_send_last(_Host, Owner) ->
     Query = case SubKey of
              GenKey ->
                GJLike = <<(node_flat_sql:encode_jid_like(GenKey))/binary, "/%">>,
-               ?SQL("select @(host)s, @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+               ?SQL("select @(host)s, @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
                     "from pubsub_state i, pubsub_node n, pubsub_node_option o "
                     "where i.nodeid = n.nodeid and n.nodeid = o.nodeid and "
                     "name='send_last_published_item' and val='on_sub_and_presence' and "
                     "(jid=%(GJ)s or jid like %(GJLike)s escape '^') and host like %(HLike)s escape '^'");
              _ ->
                SJ = node_flat_sql:encode_jid(SubKey),
-               ?SQL("select @(host)s, @(node)s, @(type)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
+               ?SQL("select @(host)s, @(node)s, @(plugin)s, @(i.nodeid)d, @(jid)s, @(subscriptions)s "
                     "from pubsub_state i, pubsub_node n, pubsub_node_option o "
                     "where i.nodeid = n.nodeid and n.nodeid = o.nodeid and "
                     "name='send_last_published_item' and val='on_sub_and_presence' and "
index 73ab74e8a35615fdaac48af106880012b0549284..b310dd2d1c3222ce6674b97c95af58c74130a687 100644 (file)
@@ -72,23 +72,20 @@ set_node(Record) when is_record(Record, pubsub_node) ->
        {result, OldNidx} ->
            catch
            ejabberd_sql:sql_query_t(
-              ?SQL("delete from pubsub_node_option where "
-                   "nodeid=%(OldNidx)d")),
+             ?SQL("delete from pubsub_node_option "
+                  "where nodeid=%(OldNidx)d")),
            catch
            ejabberd_sql:sql_query_t(
-              ?SQL("update pubsub_node set"
-                   " host=%(H)s,"
-                   " node=%(Node)s,"
-                   " parent=%(Parent)s,"
-                   " type=%(Type)s "
-                   "where nodeid=%(OldNidx)d")),
+             ?SQL("update pubsub_node set"
+                  " host=%(H)s, node=%(Node)s,"
+                  " parent=%(Parent)s, plugin=%(Type)s "
+                  "where nodeid=%(OldNidx)d")),
            OldNidx;
        _ ->
            catch
            ejabberd_sql:sql_query_t(
-              ?SQL("insert into pubsub_node(host, node, "
-                   "parent, type) values("
-                   "%(H)s, %(Node)s, %(Parent)s, %(Type)s)")),
+             ?SQL("insert into pubsub_node(host, node, parent, plugin) "
+                  "values(%(H)s, %(Node)s, %(Parent)s, %(Type)s)")),
            case nodeidx(Host, Node) of
                {result, NewNidx} -> NewNidx;
                _ -> none  % this should not happen
@@ -104,9 +101,8 @@ set_node(Record) when is_record(Record, pubsub_node) ->
                        SValue = misc:term_to_expr(Value),
                        catch
                        ejabberd_sql:sql_query_t(
-                          ?SQL("insert into pubsub_node_option(nodeid, "
-                               "name, val) values ("
-                               "%(Nidx)d, %(SKey)s, %(SValue)s)"))
+                         ?SQL("insert into pubsub_node_option(nodeid, name, val) "
+                              "values (%(Nidx)d, %(SKey)s, %(SValue)s)"))
                end,
                Record#pubsub_node.options),
            {result, Nidx}
@@ -119,8 +115,8 @@ get_node(Host, Node) ->
     H = node_flat_sql:encode_host(Host),
     case catch
        ejabberd_sql:sql_query_t(
-          ?SQL("select @(node)s, @(parent)s, @(type)s, @(nodeid)d from "
-               "pubsub_node where host=%(H)s and node=%(Node)s"))
+         ?SQL("select @(node)s, @(parent)s, @(plugin)s, @(nodeid)d from pubsub_node "
+              "where host=%(H)s and node=%(Node)s"))
     of
        {selected, [RItem]} ->
            raw_to_node(Host, RItem);
@@ -133,8 +129,8 @@ get_node(Host, Node) ->
 get_node(Nidx) ->
     case catch
        ejabberd_sql:sql_query_t(
-          ?SQL("select @(host)s, @(node)s, @(parent)s, @(type)s from "
-               "pubsub_node where nodeid=%(Nidx)d"))
+         ?SQL("select @(host)s, @(node)s, @(parent)s, @(plugin)s from pubsub_node "
+              "where nodeid=%(Nidx)d"))
     of
        {selected, [{Host, Node, Parent, Type}]} ->
            raw_to_node(Host, {Node, Parent, Type, Nidx});
@@ -151,8 +147,8 @@ get_nodes(Host) ->
     H = node_flat_sql:encode_host(Host),
     case catch
        ejabberd_sql:sql_query_t(
-          ?SQL("select @(node)s, @(parent)s, @(type)s, @(nodeid)d from "
-               "pubsub_node where host=%(H)s"))
+         ?SQL("select @(node)s, @(parent)s, @(plugin)s, @(nodeid)d from pubsub_node "
+              "where host=%(H)s"))
     of
        {selected, RItems} ->
            [raw_to_node(Host, Item) || Item <- RItems];
@@ -189,8 +185,8 @@ get_subnodes(Host, Node) ->
     H = node_flat_sql:encode_host(Host),
     case catch
        ejabberd_sql:sql_query_t(
-          ?SQL("select @(node)s, @(parent)s, @(type)s, @(nodeid)d from "
-               "pubsub_node where host=%(H)s and parent=%(Node)s"))
+         ?SQL("select @(node)s, @(parent)s, @(plugin)s, @(nodeid)d from pubsub_node "
+              "where host=%(H)s and parent=%(Node)s"))
     of
        {selected, RItems} ->
            [raw_to_node(Host, Item) || Item <- RItems];
@@ -206,14 +202,14 @@ get_subnodes_tree(Host, Node) ->
        {error, _} ->
            [];
        Rec ->
+           Type = Rec#pubsub_node.type,
            H = node_flat_sql:encode_host(Host),
            N = <<(ejabberd_sql:escape_like_arg_circumflex(Node))/binary, "/%">>,
            Sub = case catch
                ejabberd_sql:sql_query_t(
-               ?SQL("select @(node)s, @(parent)s, @(type)s, @(nodeid)d from "
-                   "pubsub_node where host=%(H)s"
-                   " and node like %(N)s escape '^'"
-                   " and \"type\"='hometree'"))
+               ?SQL("select @(node)s, @(parent)s, @(plugin)s, @(nodeid)d from pubsub_node "
+                    "where host=%(H)s and plugin=%(Type)s and"
+                    " (parent=%(Node)s or parent like %(N)s escape '^')"))
            of
                {selected, RItems} ->
                    [raw_to_node(Host, Item) || Item <- RItems];
@@ -269,14 +265,13 @@ create_node(Host, Node, Type, Owner, Options, Parents) ->
     end.
 
 delete_node(Host, Node) ->
-    H = node_flat_sql:encode_host(Host),
-    N = <<(ejabberd_sql:escape_like_arg_circumflex(Node))/binary, "/%">>,
-    Removed = get_subnodes_tree(Host, Node),
-    catch ejabberd_sql:sql_query_t(
-            ?SQL("delete from pubsub_node where host=%(H)s"
-               " and (node=%(Node)s"
-                 " or (\"type\"='hometree' and node like %(N)s escape '^'))")),
-    Removed.
+    lists:map(
+       fun(Rec) ->
+           Nidx = Rec#pubsub_node.id,
+           catch ejabberd_sql:sql_query_t(
+                   ?SQL("delete from pubsub_node where nodeid=%(Nidx)d")),
+           Rec
+       end, get_subnodes_tree(Host, Node)).
 
 %% helpers
 raw_to_node(Host, [Node, Parent, Type, Nidx]) ->
@@ -284,8 +279,8 @@ raw_to_node(Host, [Node, Parent, Type, Nidx]) ->
 raw_to_node(Host, {Node, Parent, Type, Nidx}) ->
     Options = case catch
        ejabberd_sql:sql_query_t(
-          ?SQL("select @(name)s, @(val)s from pubsub_node_option "
-               "where nodeid=%(Nidx)d"))
+         ?SQL("select @(name)s, @(val)s from pubsub_node_option "
+              "where nodeid=%(Nidx)d"))
     of
        {selected, ROptions} ->
            DbOpts = lists:map(fun ({Key, Value}) ->
@@ -308,16 +303,15 @@ raw_to_node(Host, {Node, Parent, Type, Nidx}) ->
        <<>> -> [];
        _ -> [Parent]
     end,
-    #pubsub_node{nodeid = {Host, Node},
-       parents = Parents,
-       id = Nidx, type = Type, options = Options}.
+    #pubsub_node{nodeid = {Host, Node}, id = Nidx,
+       parents = Parents, type = Type, options = Options}.
 
 nodeidx(Host, Node) ->
     H = node_flat_sql:encode_host(Host),
     case catch
        ejabberd_sql:sql_query_t(
-          ?SQL("select @(nodeid)d from pubsub_node where "
-               "host=%(H)s and node=%(Node)s"))
+         ?SQL("select @(nodeid)d from pubsub_node "
+              "where host=%(H)s and node=%(Node)s"))
     of
        {selected, [{Nidx}]} ->
            {result, Nidx};