[ARVADOS] created: 47476fa1c42eaf51963298ed4fd7cb7be1112e3e

Git user git at public.curoverse.com
Wed Feb 15 14:32:30 EST 2017


        at  47476fa1c42eaf51963298ed4fd7cb7be1112e3e (commit)


commit 47476fa1c42eaf51963298ed4fd7cb7be1112e3e
Author: Tom Clegg <tom at curoverse.com>
Date:   Wed Feb 15 14:31:20 2017 -0500

    9849: Fix expensive "all readable collections" query.

diff --git a/services/api/app/models/container.rb b/services/api/app/models/container.rb
index 7731a8d..36f3616 100644
--- a/services/api/app/models/container.rb
+++ b/services/api/app/models/container.rb
@@ -94,31 +94,24 @@ class Container < ArvadosModel
     # Check for Completed candidates that had consistent outputs.
     completed = candidates.where(state: Complete).where(exit_code: 0)
     outputs = completed.select('output').group('output').limit(2)
-    if outputs.count.count != 1
-      Rails.logger.debug("Found #{outputs.count.length} different outputs")
-    elsif Collection.
+    case outputs.count.count
+    when 0
+    when 1
+      select_readable_pdh = Collection.
         readable_by(current_user).
-        where(portable_data_hash: outputs.first.output).
-        count < 1
+        select(:portable_data_hash).
+        to_sql
+      usable = completed.
+        order('finished_at ASC').
+        where("log IN (#{select_readable_pdh})").
+        where("output IN (#{select_readable_pdh})").
+        first
+      return usable if usable
       Rails.logger.info("Found reusable container(s) " +
-                        "but output #{outputs.first} is not readable " +
+                        "but none with both output and log readable " +
                         "by user #{current_user.uuid}")
     else
-      # Return the oldest eligible container whose log is still
-      # present and readable by current_user.
-      readable_pdh = Collection.
-        readable_by(current_user).
-        select('portable_data_hash')
-      completed = completed.
-        where("log in (#{readable_pdh.to_sql})").
-        order('finished_at asc').
-        limit(1)
-      if completed.first
-        return completed.first
-      else
-        Rails.logger.info("Found reusable container(s) but none with a log " +
-                          "readable by user #{current_user.uuid}")
-      end
+      Rails.logger.debug("Found #{outputs.count.length} different outputs")
     end
 
     # Check for Running candidates and return the most likely to finish sooner.

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list