-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use table name when generating SQL to filter tasks on Tasks
screen
#344
Use table name when generating SQL to filter tasks on Tasks
screen
#344
Conversation
…rm always correctly defined. Only task queries requier adding table name when accessing filed (after creating association between Job and MiqTask sql is joining 2 tables with the same column names), Job queries still the same.
Tasks
screen Tasks
screen
9110973
to
deda7d7
Compare
deda7d7
to
36af099
Compare
7e305ae
to
ee1f3a9
Compare
ee1f3a9
to
5b0118a
Compare
@yrudman Is there a "before" screen shot that goes with the "after" one? IIRC, there should not be any visible UI changes with this PR. I should just ensure the UI still works with you backend changes. |
@gtanzillo Deleting 3 records linked to |
@mzazrivec could you review |
end | ||
|
||
@user_names = db_class.distinct("userid").pluck("userid").delete_if(&:blank?) if @active_tab.to_i > 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this has been there before, but is there perhaps a better way to do this? (select non-null user names
that have ever queued a job or a task). Esp. since miq_task.userid is a varchar and isn't indexed.
@kbrock ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mzazrivec This is good point!
Should that improvement belong to another PR ?
I was not aware that we keep history of users accessing specific screens/performing action. If we do, that table should be pretty big (vs users
table) and which way is faster - need some benchmarking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is getting the list of every user who has ever created a job or task?
Yea, I'd imagine the tasks table is much bigger than the users table.
All the queries I imagine depend upon having an index on userid. do we want to add that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh, I've misunderstood Milan's comment, user
table is not involved here. @kbrock it may make sense to add index on userid
in jobs
and miq_tasks
tables. I am not sure since there is trade-off on creating index...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, there is a tradeoff on creating tasks vs searching this screen.
And since we create a bunch of tasks that are not in the ui, this may be a hit we don't want.
Do we have another mechanism to pick users?
Since this is just moving code (not creating it), I think fixing this is for another PR
trivial change, loose the parameter to distinct
- it is not necessary due to the pluck
-@user_names = db_class.distinct("userid").pluck("userid").delete_if(&:blank?) if @active_tab.to_i > 2
+@user_names = db_class.distinct.pluck("userid").delete_if(&:blank?) if @active_tab.to_i > 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you Keenan for suggestion! Done
@gtanzillo, @dclarizio result of this query supposed to populate Users
filter but at this time this filter not visible. I will create separate PR to make User
filter visible on appropriate tabs
if vm_analysis_task? | ||
[sql, %w(finished waiting_to_start queued)] | ||
else | ||
[sql, %w(Finished waiting_to_start Queued)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the backend part, so I need to ask: why the upper case / lower case difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dynamic SQL generated against 2 different tables: jobs
table (for tabs tasks_1
and tasks_3
, when vm_analysis_task?=true
) and miq_tasks
table (for tabs task_2
and tasks_4
)
state
column present in both tables, but values are different: in jobs
table there are starting with low case and in miq_tasks
with with upper case. List of values to populate state filter for jobs
table: https://github.com/ManageIQ/manageiq-ui-classic/blob/master/app/helpers/ui_constants.rb#L410
and for miq_tasks
table: https://github.com/ManageIQ/manageiq-ui-classic/blob/master/app/helpers/ui_constants.rb#L415
There is waiting_to_start
value in downcase which should not be there (https://github.com/ManageIQ/manageiq-ui-classic/blob/master/app/controllers/miq_task_controller.rb#L403), and may be we should delete it, however it is there from the beginning and I am not sure if it is some legitimate exception or old bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pruning the code down.
Do we have general style suggestions on using @variables
or munging sql?
good call Milan on the distinct users column. That will bite us.
"(miq_tasks.state!=? AND miq_tasks.state!=? AND miq_tasks.state!=?)) AND "\ | ||
"miq_tasks.updated_on>=? AND "\ | ||
"miq_tasks.updated_on<=? AND "\ | ||
"miq_tasks.state=?" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you didn't write this.
but miq_tasks.state
is confusing here (in these specs in general)
end | ||
end | ||
|
||
def get_jobs(conditions) | ||
def list_jobs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something is nice about having the conditions explicitly passed into this method.
but it is duplicated in many places, so this will do
@@ -334,6 +322,9 @@ def tasks_set_default_options | |||
# Create a condition from the passed in options | |||
def tasks_condition(opts, use_times = true) | |||
cond = [[]] | |||
|
|||
cond = add_to_condition(cond, "jobs.guid IS NULL", nil) unless vm_analysis_task? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not for today (or possibly ever) but...
active record's where()
already builds queries for us. seems odd we are reinventing this wheel
@@ -394,32 +385,40 @@ def build_query_for_warn | |||
end | |||
|
|||
def build_query_for_status_completed(status) | |||
return ["(state=? AND status=?)", ["finished", status]] if vm_analysis_task? | |||
["(state=? AND status=?)", ["Finished", status.capitalize]] | |||
return ["(#{db_table}state=? AND #{db_table}status=?)", ["finished", status]] if vm_analysis_task? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the way you formatted the sql code in build_query_for_running
and other places with a common sql block up top.
Would it make sense to do that change here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, it does make sense to format in the same way, will do. Btw, reason for formatting was to make miq-bot happy and remove long lines and since that line was not long it wasn't touched
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kbrock sql formating looks nicer now
@@ -851,6 +854,17 @@ | |||
end | |||
end | |||
|
|||
describe "#list_jobs" do | |||
it 'sets the active tab' do | |||
controller.instance_variable_set(:@tabform, "ui_2") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, this is a side effect of all of those @
variables vs passing in the variables into list_jobs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to minimize changes in this PR and did not remove global variables as aproach to pass parameter into methods.
end | ||
|
||
@user_names = db_class.distinct("userid").pluck("userid").delete_if(&:blank?) if @active_tab.to_i > 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is getting the list of every user who has ever created a job or task?
Yea, I'd imagine the tasks table is much bigger than the users table.
All the queries I imagine depend upon having an index on userid. do we want to add that?
Checked commits yrudman/manageiq-ui-classic@3dd0a2a~...171d44c with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes some nice changes.
Also nicely cleans it up in prep for merging those 2 models
👍
@miq-bot remove-label pending core |
@mzazrivec @dclarizio back-end PR has been merged - ManageIQ/manageiq#13452 |
This PR depends and should be merged together with ManageIQ/manageiq#13452
There would be task created for each job after changes in ManageIQ/manageiq#13452 and those new tasks associated with jobs should be filtered out on
UI Tasks
screen.Since there are columns in
jobs
andmiq_tasks
tables with same name (likestate
,status
,...) we need to use table name when generating SQL on joined tables.@miq-bot add-label enhancement
local AFTER UI and model changes:
![after](https://cloud.githubusercontent.com/assets/6556758/22808629/0495a430-eefb-11e6-81c0-8627bf50fc50.png)
\cc @Fryguy @gtanzillo @dclarizio