[mew-dist 28124] smew高速化

KOIE Hidetaka ( 鯉江英隆 ) hide at example.com
2008年 2月 25日 (月) 18:25:40 JST


子孫を探していくときに
select文を一人ずつ発行する代りに
世代ごとに発行するようにするパッチです。
スレッドが枝分かれしている場合に効果があります。

大きいスレッドで試してみると 19秒→11秒 でした。
ex: smew id.db '<20021210.151128.74731846.maechan at example.com>'

--- smew	2008-02-19 20:28:06.665035116 +0900
+++ smew2	2008-02-25 18:05:18.507194140 +0900
@@ -25,9 +25,16 @@
   return ret
 end
 
-def select_by_parid(hash, db, id, mydir)
+def select_by_parid(hash, db, idvec, mydir)
   ret = []
-  db.execute("SELECT * FROM mew WHERE (mew.parid = '#{id}');") do |ent|
+  cond = ""
+  idvec.each do |id|
+    if cond != ""
+      cond += " OR "
+    end
+    cond += "mew.parid = '#{id}'"
+  end
+  db.execute("SELECT * FROM mew WHERE (#{cond});") do |ent|
     if push_results(hash, ent, mydir)
       ret.push(ent)
     end
@@ -80,13 +87,13 @@
 end
 
 def search_descendants(hash, db, myid, mydir)
-  parents = select_by_parid(hash, db, myid, mydir)
+  parents = select_by_parid(hash, db, [myid], mydir)
   while parents != []
-    children = []
+    idvec = []
     parents.each do |ent|
-      children += select_by_parid(hash, db, ent['id'], mydir)
+      idvec.push(ent['id'])
     end
-    parents = children
+    parents = select_by_parid(hash, db, idvec, mydir)
   end
 end

--
KOIE Hidetaka <hide at example.com>



Mew-dist メーリングリストの案内