From 35c2572761bb060aa1c12f417f97aa9e1ccbe7eb Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Fri, 21 Apr 2017 15:17:46 -0400 Subject: [PATCH] 11517: Use count=none when retrieving logs. --- apps/workbench/app/controllers/keep_disks_controller.rb | 1 + apps/workbench/app/controllers/users_controller.rb | 1 + apps/workbench/app/models/arvados_base.rb | 4 ++++ apps/workbench/app/models/arvados_resource_list.rb | 6 ++++++ apps/workbench/app/models/job.rb | 2 +- apps/workbench/app/models/pipeline_instance.rb | 7 ++++--- apps/workbench/app/models/proxy_work_unit.rb | 1 + 7 files changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/workbench/app/controllers/keep_disks_controller.rb b/apps/workbench/app/controllers/keep_disks_controller.rb index f57455b37f..bbf18e591b 100644 --- a/apps/workbench/app/controllers/keep_disks_controller.rb +++ b/apps/workbench/app/controllers/keep_disks_controller.rb @@ -32,6 +32,7 @@ class KeepDisksController < ApplicationController histogram_log = Log. filter([[:event_type, '=', 'block-age-free-space-histogram']]). order(:created_at => :desc). + with_count('none'). limit(1) histogram_log.each do |log_entry| # We expect this block to only execute at most once since we diff --git a/apps/workbench/app/controllers/users_controller.rb b/apps/workbench/app/controllers/users_controller.rb index d2fcbbb94c..1a1c5f8021 100644 --- a/apps/workbench/app/controllers/users_controller.rb +++ b/apps/workbench/app/controllers/users_controller.rb @@ -102,6 +102,7 @@ class UsersController < ApplicationController filter([[:object_uuid, '=', u.uuid], [:event_type, '=', 'user-storage-report']]). order(:created_at => :desc). + with_count('none'). limit(1) storage_log.each do |log_entry| # We expect this block to only execute once since we specified limit(1) diff --git a/apps/workbench/app/models/arvados_base.rb b/apps/workbench/app/models/arvados_base.rb index 6250daa06a..5d6a4c94b9 100644 --- a/apps/workbench/app/models/arvados_base.rb +++ b/apps/workbench/app/models/arvados_base.rb @@ -144,6 +144,10 @@ class ArvadosBase < ActiveRecord::Base ArvadosResourceList.new(self).select(*args) end + def self.with_count(*args) + ArvadosResourceList.new(self).with_count(*args) + end + def self.distinct(*args) ArvadosResourceList.new(self).distinct(*args) end diff --git a/apps/workbench/app/models/arvados_resource_list.rb b/apps/workbench/app/models/arvados_resource_list.rb index 27069706fb..e56d1981e3 100644 --- a/apps/workbench/app/models/arvados_resource_list.rb +++ b/apps/workbench/app/models/arvados_resource_list.rb @@ -84,6 +84,11 @@ class ArvadosResourceList self end + def with_count(count_param='exact') + @count = count_param + self + end + def fetch_multiple_pages(f) @fetch_multiple_pages = f self @@ -178,6 +183,7 @@ class ArvadosResourceList api_params = { _method: 'GET' } + api_params[:count] = @count if @count api_params[:where] = @cond if @cond api_params[:eager] = '1' if @eager api_params[:select] = @select if @select diff --git a/apps/workbench/app/models/job.rb b/apps/workbench/app/models/job.rb index 346aef35d2..128440d526 100644 --- a/apps/workbench/app/models/job.rb +++ b/apps/workbench/app/models/job.rb @@ -43,7 +43,7 @@ class Job < ArvadosBase end def stderr_log_query(limit=nil) - query = Log.where(object_uuid: self.uuid).order("created_at DESC") + query = Log.where(object_uuid: self.uuid).order("created_at DESC").with_count('none') query = query.limit(limit) if limit query end diff --git a/apps/workbench/app/models/pipeline_instance.rb b/apps/workbench/app/models/pipeline_instance.rb index b6e0ef17ae..1c14efffa6 100644 --- a/apps/workbench/app/models/pipeline_instance.rb +++ b/apps/workbench/app/models/pipeline_instance.rb @@ -103,9 +103,10 @@ class PipelineInstance < ArvadosBase def stderr_log_query(limit=nil) query = Log. - where(event_type: "stderr", - object_uuid: stderr_log_object_uuids). - order("id DESC") + with_count('none'). + where(event_type: "stderr", + object_uuid: stderr_log_object_uuids). + order("created_at DESC") unless limit.nil? query = query.limit(limit) end diff --git a/apps/workbench/app/models/proxy_work_unit.rb b/apps/workbench/app/models/proxy_work_unit.rb index 42304843d3..b7cc6a0f19 100644 --- a/apps/workbench/app/models/proxy_work_unit.rb +++ b/apps/workbench/app/models/proxy_work_unit.rb @@ -309,6 +309,7 @@ class ProxyWorkUnit < WorkUnit Log.where(object_uuid: log_object_uuids). order("created_at DESC"). limit(limit). + with_count('none'). select { |log| log.properties[:text].is_a? String }. reverse. flat_map { |log| log.properties[:text].split("\n") } -- 2.30.2