Merge lp:~dkessel/ubuntu-qa-website/fix-date-filtering into lp:ubuntu-qa-website

Proposed by Daniel Kessel
Status: Merged
Merged at revision: 403
Proposed branch: lp:~dkessel/ubuntu-qa-website/fix-date-filtering
Merge into: lp:ubuntu-qa-website
Diff against target: 75 lines (+26/-13)
2 files modified
modules/qatracker/qatracker.functions.php (+14/-9)
modules/qatracker/user/qatracker.user.builds.php (+12/-4)
To merge this branch: bzr merge lp:~dkessel/ubuntu-qa-website/fix-date-filtering
Reviewer Review Type Date Requested Status
Nicholas Skaggs (community) Approve
Daniel Kessel (community) Needs Resubmitting
Review via email: mp+240175@code.launchpad.net

Description of the change

This branch fixes two issues:

1. It fixes the currently broken SQL query that is generated when entering anything into the date range text fields. The current code refers to a non-existing database field...
2. It sets the default date range in all date filters in the website to be "from today minus 31 days until today", so those expensive queries are no longer performed by default.

To post a comment you must log in.
403. By Daniel Kessel

convert tabs to spaces. use single quotes instead for double quotes in the modified code lines. rename date variables for consistency.

Revision history for this message
Daniel Kessel (dkessel) wrote :

This is ready for a new review.

I fixed the following issues that came up yesterday:
- usage of a mix of single and double quotes => I now use single quotes throughout the modified code
- inconsistent naming - the existing code used 'date_to', I used 'to_date' => I changed those variable names to match the existing code

I also noticed the rest of the code was using space instead of tabs, so I fixed that too and converted all of my tabs to spaces.

review: Needs Resubmitting
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

+1 now from me. 30 days seems reasonable, and we can adjust if prod still feels like it's taking too long.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/qatracker/qatracker.functions.php'
2--- modules/qatracker/qatracker.functions.php 2013-06-26 03:09:53 +0000
3+++ modules/qatracker/qatracker.functions.php 2014-10-31 06:54:11 +0000
4@@ -626,29 +626,34 @@
5
6 $items['datefilter'] = array(
7 '#type' => 'fieldset',
8- '#title' => t("Filter results by time"),
9+ '#title' => t('Filter results by time'),
10 '#collapsible' => true,
11 '#collapsed' => true,
12 );
13
14+ $date_from = new DateTime();
15+ $date_from->sub(new DateInterval('P31D'));
16+
17 $items['datefilter']['date_from'] = array(
18 '#type' => 'textfield',
19- '#title' => t("Shows result from"),
20- '#attributes' => array('class' => array('datepicker')),
21- '#description' => t("Date in MM/DD/YYYY format. Time is 00:00 unless manually specified.")
22+ '#title' => t('Shows result from'),
23+ '#attributes' => array('class' => array('datepicker'), 'value' => $date_from->format('m/d/Y')),
24+ '#description' => t('Date in MM/DD/YYYY format.')
25 );
26
27+ $date_to = new DateTime();
28+
29 $items['datefilter']['date_to'] = array(
30 '#type' => 'textfield',
31- '#title' => t("Show results to"),
32- '#attributes' => array('class' => array('datepicker')),
33- '#description' => t("Date in MM/DD/YYYY format. Time is 00:00 unless manually specified.")
34+ '#title' => t('Show results to'),
35+ '#attributes' => array('class' => array('datepicker'), 'value' => $date_to->format('m/d/Y')),
36+ '#description' => t('Date in MM/DD/YYYY format.')
37 );
38
39 $items['datefilter']['submit'] = array(
40 '#type' => 'submit',
41- '#submit' => array("qatracker_filter_by_date_submit"),
42- '#value' => t("Filter results"),
43+ '#submit' => array('qatracker_filter_by_date_submit'),
44+ '#value' => t('Filter results'),
45 );
46
47 return $items;
48
49=== modified file 'modules/qatracker/user/qatracker.user.builds.php'
50--- modules/qatracker/user/qatracker.user.builds.php 2013-06-25 19:02:45 +0000
51+++ modules/qatracker/user/qatracker.user.builds.php 2014-10-31 06:54:11 +0000
52@@ -118,11 +118,19 @@
53 $query->condition('qatracker_build_milestone.status', array(0, 1, 4), "IN");
54 }
55 else {
56- if(array_key_exists("date_from", $_POST) && $_POST['date_from']) {
57- $query->condition('qatracker_build.date', DateTime::createFromFormat('m/d/Y', $_POST['date_from'])->format("Ymd"), ">=");
58+ if(array_key_exists('date_from', $_POST) && $_POST['date_from']) {
59+ $query->condition('qatracker_build_milestone.date', DateTime::createFromFormat('m/d/Y', $_POST['date_from'])->format('Ymd'), '>=');
60+ } else {
61+ $date_from = new DateTime();
62+ $date_from->sub(new DateInterval('P31D'));
63+ $query->condition('qatracker_build_milestone.date', $date_from->format('Ymd'), '>=');
64 }
65- if(array_key_exists("date_to", $_POST) && $_POST['date_to']) {
66- $query->condition('qatracker_build.date', DateTime::createFromFormat('m/d/Y', $_POST['date_to'])->format("Ymd"), "<=");
67+
68+ if(array_key_exists('date_to', $_POST) && $_POST['date_to']) {
69+ $query->condition('qatracker_build_milestone.date', DateTime::createFromFormat('m/d/Y', $_POST['date_to'])->format('Ymd'), '<=');
70+ } else {
71+ $date_to = new DateTime();
72+ $query->condition('qatracker_build_milestone.date', $date_to->format('Ymd'), '<=');
73 }
74 }
75 $query->condition('qatracker_build_milestone.milestoneid', $milestoneid);

Subscribers

People subscribed via source and target branches