Skip to content

Commit

Permalink
Merge pull request #58 from rhelmer/bug637661-add-pagination-and-dura…
Browse files Browse the repository at this point in the history
…tion

Bug637661 add pagination and duration
  • Loading branch information
brandonsavage committed Oct 6, 2011
2 parents dbb60b6 + 34788ed commit afc45b9
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 108 deletions.
2 changes: 1 addition & 1 deletion socorro/cron/hangReport.py
Expand Up @@ -16,7 +16,7 @@ def run(config):
connection, cursor = databaseConnectionPool.connectionCursorPair()

startTime = datetime.now() - timedelta(day=1)
cursor.callproc('hang_report', (startTime))
cursor.callproc('update_hang_report', (startTime))
connection.commit()
finally:
databaseConnectionPool.cleanup()
Expand Down
41 changes: 32 additions & 9 deletions socorro/services/hangReport.py
Expand Up @@ -11,17 +11,38 @@ def __init__(self, configContext):
super(HangReport, self).__init__(configContext)
logger.debug('HangReport __init__')

# http://socorro-api/bpapi/201109/reports/hang/p/Firefox/v/9.0a1/end/2011-09-20T15%3A00%3A00T%2B0000/days/1/listsize/300
uri = '/201109/reports/hang/p/(.*)/v/(.*)/end/(.*)/duration/(.*)/listsize/(.*)'
# http://socorro-api/bpapi/201109/reports/hang/p/Firefox/v/9.0a1/end/2011-09-20T15%3A00%3A00T%2B0000/days/1/listsize/300/page/1
uri = '/201109/reports/hang/p/(.*)/v/(.*)/end/(.*)/duration/(.*)/listsize/(.*)/page/(.*)'

def get(self, *args):
convertedArgs = webapi.typeConversion([str, str, dtutil.datetimeFromISOdateString, int, int], args)
parameters = util.DotDict(zip(['product', 'version', 'end', 'duration', 'listsize'], convertedArgs))
convertedArgs = webapi.typeConversion([str, str, dtutil.datetimeFromISOdateString, int, int, int], args)
parameters = util.DotDict(zip(['product', 'version', 'end', 'duration', 'listsize', 'page'], convertedArgs))

connection = self.database.connection()
cursor = connection.cursor()

hangReport = """
hangReportCountSql = """
/* socorro.services.HangReportCount */
SELECT count(*)
FROM hang_report
WHERE product = %(product)s
AND version = %(version)s
AND report_day > utc_day_begins_pacific(((%(end)s)::timestamp - interval '%(duration)s days')::date)
"""

logger.debug(cursor.mogrify(hangReportCountSql, parameters))
cursor.execute(hangReportCountSql, parameters)

hangReportCount = cursor.fetchone()[0]

listsize = parameters['listsize']
page = parameters['page']
totalPages = hangReportCount / listsize
logger.debug('total pages: %s' % totalPages)

parameters['offset'] = listsize * (page - 1)

hangReportSql = """
/* socorro.services.HangReport */
SELECT browser_signature, plugin_signature,
browser_hangid, flash_version, url,
Expand All @@ -30,10 +51,11 @@ def get(self, *args):
WHERE product = %(product)s
AND version = %(version)s
AND report_day > utc_day_begins_pacific(((%(end)s)::timestamp - interval '%(duration)s days')::date)
LIMIT %(listsize)s"""
LIMIT %(listsize)s
OFFSET %(offset)s"""

logger.debug(cursor.mogrify(hangReport, parameters))
cursor.execute(hangReport, parameters)
logger.debug(cursor.mogrify(hangReportSql, parameters))
cursor.execute(hangReportSql, parameters)

result = []
for row in cursor.fetchall():
Expand All @@ -47,4 +69,5 @@ def get(self, *args):
'uuid': uuid,
'duplicates': duplicates,
'report_day': str(report_day)})
return {'hangReport': result, 'end_date': str(parameters['end'])}
return {'hangReport': result, 'endDate': str(parameters['end']), 'totalPages': totalPages, 'currentPage': page,
'totalCount': hangReportCount}
2 changes: 1 addition & 1 deletion sql/upgrade/2.3/hang_report.sql
Expand Up @@ -22,7 +22,7 @@ CREATE OR REPLACE FUNCTION update_hang_report(updateday DATE) RETURNS BOOLEAN
-- created for bug 637661

INSERT INTO hang_report (
SELECT
SELECT DISTINCT
product_name AS product,
version_string AS version,
browser.signature AS browser_signature,
Expand Down
20 changes: 13 additions & 7 deletions webapp-php/application/controllers/hangreport.php
Expand Up @@ -95,7 +95,7 @@ public function index() {
* @param string The crash type to query by
* @return void
*/
public function byversion($product=null, $version=null, $duration=null, $crash_type=null)
public function byversion($product=null, $version=null)
{
if(is_null($product)) {
Kohana::show_404();
Expand All @@ -107,12 +107,13 @@ public function byversion($product=null, $version=null, $duration=null, $crash_t
$this->_versionExists($version);
}

$duration = (int)Input::instance()->get('duration');
if (empty($duration)) {
$duration = Kohana::config('products.duration');
}

$duration_url_path = array(Router::$controller, Router::$method, $product, $version);
$durations = Kohana::config('hang_report.durations');
$page = (int)Input::instance()->get('page');
$page = (!empty($page) && $page > 0) ? $page : 1;

$config = array();
$credentials = Kohana::config('webserviceclient.basic_auth');
Expand All @@ -131,19 +132,24 @@ public function byversion($product=null, $version=null, $duration=null, $crash_t

$p = urlencode($product);
$v = urlencode($version);
$resp = $this->hangreport_model->getHangReportViaWebService($p, $v, $duration);
$pg = urlencode($page);
$resp = $this->hangreport_model->getHangReportViaWebService($p, $v, $duration, $pg);

if ($resp) {
$pager = new MozPager(Kohana::config('hang_report.byversion_limit'), $resp->totalCount, $resp->currentPage);

$this->setViewData(array(
'resp' => $resp,
'duration_url' => url::site(implode($duration_url_path, '/') . '/'),
'duration' => $duration,
'durations' => $durations,
'product' => $product,
'version' => $version,
'nav_selection' => 'hang_report',
'end_date' => $resp->end_date,
'end_date' => $resp->endDate,
'url_base' => url::site('hangreport/byversion/'.$product.'/'.$version),
'url_nav' => url::site('products/'.$product),
'pager' => $pager,
'totalItemText' => " Results",
'navPathPrefix' => url::site('hangreport/byversion/'.$product.'/'.$version) . '?duration=' . $duration . '&page=',
));
} else {
header("Data access error", TRUE, 500);
Expand Down
5 changes: 3 additions & 2 deletions webapp-php/application/models/hangreport.php
Expand Up @@ -12,7 +12,7 @@ class HangReport_Model extends Model {
* @param int The number of days
* @return array Returns
*/
public function getHangReportViaWebService($product, $version, $duration)
public function getHangReportViaWebService($product, $version, $duration, $page)
{
$config = array();
$credentials = Kohana::config('webserviceclient.basic_auth');
Expand All @@ -27,8 +27,9 @@ public function getHangReportViaWebService($product, $version, $duration)
$lifetime = Kohana::config('products.cache_expires');
$p = urlencode($product);
$v = urlencode($version);
$pg = urlencode($page);

$resp = $service->get("${host}/201109/reports/hang/p/${p}/v/${v}/end/${end_date}/duration/${duration}/listsize/${limit}");
$resp = $service->get("${host}/201109/reports/hang/p/${p}/v/${v}/end/${end_date}/duration/${duration}/listsize/${limit}/page/${pg}");
if($resp) {
return $resp;
}
Expand Down
53 changes: 25 additions & 28 deletions webapp-php/application/views/hangreport/byversion.php
Expand Up @@ -16,6 +16,11 @@
<ul class="options">
<li><a href="<?php echo url::base(); ?>hangreport/byversion/<?php echo $product ?>/<?php echo $version ?>" class="selected">By Product/Version</a></li>
</ul>
<ul class="options">
<li><a href="<?php out::H($url_base); ?>?duration=3" <?php if ($duration == 3) echo ' class="selected"'; ?>>3 days</a></li>
<li><a href="<?php out::H($url_base); ?>?duration=7" <?php if ($duration == 7) echo ' class="selected"'; ?>>7 days</a></li>
<li><a href="<?php out::H($url_base); ?>?duration=14" <?php if ($duration == 14) echo ' class="selected"'; ?>>14 days</a></li>
</ul>
</div>


Expand All @@ -36,30 +41,28 @@
}
?>
<th class="header">OOID</th>
<th class="header">Duplicates</th>
<th class="header">Report Day</th>
</tr>
</thead>
<tbody>
<?php
if ($resp) {
View::factory('moz_pagination/nav')->render(TRUE);
foreach ($resp->hangReport as $entry) {
$sigParams = array(
#'range_value' => $range_value,
#'range_unit' => $range_unit,
'date' => $end_date,
'signature' => $entry->browser_signature
);
if (property_exists($entry, 'branch')) {
$sigParams['branch'] = $entry->branch;
} else {
$sigParams['version'] = $product . ':' . $version;
}

$browser_link_url = url::base() . 'report/list?' . html::query_string($sigParams);
$sigParams['signature'] = $entry->plugin_signature;
$plugin_link_url = url::base() . 'report/list?' . html::query_string($sigParams);
$uuid_link_url = url::base() . 'report/index/' . $entry->uuid;
$sigParams = array(
'date' => $end_date,
'signature' => $entry->browser_signature
);
if (property_exists($entry, 'branch')) {
$sigParams['branch'] = $entry->branch;
} else {
$sigParams['version'] = $product . ':' . $version;
}

$browser_link_url = url::base() . 'report/list?' . html::query_string($sigParams);
$sigParams['signature'] = $entry->plugin_signature;
$plugin_link_url = url::base() . 'report/list?' . html::query_string($sigParams);
$uuid_link_url = url::base() . 'report/index/' . $entry->uuid;
?>
<tr>
<td>
Expand All @@ -85,25 +88,19 @@
<a href="<?php out::H($uuid_link_url)?>"><?php out::H($entry->uuid) ?></a>
</td>
<td>
<?php
foreach ($entry->duplicates as $dup) {
?>
<?php out::H($dup) ?>
<?php
}
?>
</td>
<td>
<?php out::H($entry->report_day) ?>
</td>
</tr>
<?php
}
?>
<tbody>
</table>
<?php
View::factory('moz_pagination/nav')->render(TRUE);
} else {
View::factory('common/data_access_error')->render(TRUE);
}
?>
<tbody>
</table>
</div>
</div>
60 changes: 0 additions & 60 deletions webapp-php/application/views/hangreport/index.php

This file was deleted.

0 comments on commit afc45b9

Please sign in to comment.