Index: www/sites/all/themes/scan/np-scan-analytics-scans.tpl.php
===================================================================
--- www/sites/all/themes/scan/np-scan-analytics-scans.tpl.php (revision 34382)
+++ www/sites/all/themes/scan/np-scan-analytics-scans.tpl.php (working copy)
@@ -88,13 +88,13 @@
online, 'Scan Online', 'Scans Online'); ?>
- views; ?>
- views, 'View', 'Views'); ?>
+ page_all; ?>
+ page_all, 'View', 'Views'); ?>
- views_24; ?>
- views, 'View', 'Views'); ?>
+ page_today; ?>
+ page_today, 'View', 'Views'); ?>
@@ -147,7 +147,7 @@
$graph_name = ((empty($scan->scan_status)) ? 'd-' : ''). $json_name . $scan->nid;
switch ($page) {
case 'views':
- $data = $timeframe == 24 ? $scan->stats->np_views_page_24 : $scan->stats->np_views_page;
+ $data = $timeframe == 24 ? $scan->stats->page_today : $scan->stats->page_all;
$type = 'View';
break;
@@ -277,16 +277,16 @@
-
- stats->np_views_page_24), '1 Page View in the last 24 hours', '@count Page Views in the last 24 hours')?>
+ stats->page_today), '1 Page View in the last 24 hours', '@count Page Views in the last 24 hours')?>
-
- stats->np_views_page), '1 Page View all time', '@count Page Views all time')?>
+ stats->page_all), '1 Page View all time', '@count Page Views all time')?>
-
- stats->np_views_widget_24), '1 Widget View in the last 24 hours', '@count Widget Views in the last 24 hours')?>
+ stats->widget_today), '1 Widget View in the last 24 hours', '@count Widget Views in the last 24 hours')?>
-
- stats->np_views_widget), '1 Widget View all time', '@count Widget Views all time')?>
+ stats->widget_all), '1 Widget View all time', '@count Widget Views all time')?>
-
recommendations_24, '1 Recommendation in the last 24 hours', '@count Recommendations in the last 24 hours')?>
Index: www/sites/all/modules/custom/np_scan/np_scan.analytics.inc
===================================================================
--- www/sites/all/modules/custom/np_scan/np_scan.analytics.inc (revision 34382)
+++ www/sites/all/modules/custom/np_scan/np_scan.analytics.inc (working copy)
@@ -56,14 +56,11 @@
// get the basic order
$rs = db_query_range("
SELECT ss.active_vid as vid
- FROM {node} n
- INNER JOIN {scan_settings} ss ON n.nid = ss.nid AND ss.status = %d
- WHERE n.nid IN (
- SELECT o.nid
- FROM {og_ancestry} o
- WHERE o.group_nid IN (" . $client_id_placeholders . ")
- )
- ORDER BY ". ($timeframe == 24 ? 'n.np_views_24' : 'n.np_views_page') ." DESC
+ FROM {scan_hits} h
+ INNER JOIN {scan_settings} ss ON h.nid = ss.nid AND ss.status = %d
+ INNER JOIN {og_ancestry} o ON h.nid = o.nid
+ WHERE o.group_nid IN (" . $client_id_placeholders . ")
+ ORDER BY ". ($timeframe == 24 ? 'h.page_today' : 'h.page_last') ." DESC
", $args, 0, $limit);
while ($row = db_fetch_object($rs)) {
$scans[$row->$key] = FALSE;
@@ -101,9 +98,12 @@
$scan_placeholders = implode(',', array_fill(0, count($scans), '%d'));
$rs = db_query("
SELECT s.scan_id, s.nid, s.vid,
- n.np_views_page, n.np_views_24 AS np_views_page_24, n.np_views_widget, n.np_views_widget_24
+ h.page_all,
+ h.page_today,
+ h.widget_all,
+ h.widget_today
FROM {scan} s
- INNER JOIN {node} n ON n.nid = s.nid
+ INNER JOIN {scan_hits} h ON h.nid = s.nid
WHERE s." . $key . " IN ( " . $scan_placeholders . ")
", array_keys($scans));
while ($statistics = db_fetch_object($rs)) {
@@ -215,14 +215,16 @@
scan_api_set_active_shard('misc');
// Some general statistics
$statistics = db_fetch_object(db_query("
- SELECT SUM(ss.status) AS online, COUNT(*) AS count, SUM(n.np_views_24) AS views_24, SUM(n.np_views_page) AS views, SUM(n.np_views_widget) AS widget_views
- FROM {node} n
- INNER JOIN {scan_settings} ss ON n.nid = ss.nid
- WHERE n.nid IN (
- SELECT o.nid
- FROM {og_ancestry} o
- WHERE o.group_nid IN (" . $client_id_placeholders . ")
- )
+ SELECT SUM(ss.status) AS online,
+ COUNT(*) AS count,
+ SUM(h.page_today) AS page_today,
+ SUM(h.page_all) AS page_all,
+ SUM(h.widget_today) AS widget_today,
+ SUM(h.widget_all) AS widget_all
+ FROM {scan_hits} h
+ INNER JOIN {scan_settings} ss ON h.nid = ss.nid
+ INNER JOIN {og_ancestry} o ON h.nid = o.nid
+ WHERE o.group_nid IN (" . $client_id_placeholders . ")
", $client_ids));
scan_api_set_active_shard();
Index: www/sites/all/modules/custom/np_scan/views/np_scan.scan_search.view
===================================================================
--- www/sites/all/modules/custom/np_scan/views/np_scan.scan_search.view (revision 34382)
+++ www/sites/all/modules/custom/np_scan/views/np_scan.scan_search.view (working copy)
@@ -359,7 +359,7 @@
'number_decimals' => '0',
'show_not_available' => 1,
),
- 'np_views_24' => array(
+ 'page_today' => array(
'label' => 'Page Views (24hrs)',
'alter' => array(
'alter_text' => 0,
@@ -370,6 +370,7 @@
'alt' => '',
'prefix' => '',
'suffix' => '',
+ 'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
@@ -378,6 +379,9 @@
'strip_tags' => 0,
'html' => 0,
),
+ 'empty' => '',
+ 'hide_empty' => 0,
+ 'empty_zero' => 0,
'set_precision' => FALSE,
'precision' => 0,
'decimal' => '.',
@@ -385,15 +389,12 @@
'prefix' => '',
'suffix' => '',
'exclude' => 0,
- 'id' => 'np_views_24',
- 'table' => 'node',
- 'field' => 'np_views_24',
- 'override' => array(
- 'button' => 'Override',
- ),
+ 'id' => 'page_today',
+ 'table' => 'scan_hits',
+ 'field' => 'page_today',
'relationship' => 'none',
),
- 'np_views_page' => array(
+ 'page_all' => array(
'label' => 'Page Views (all)',
'alter' => array(
'alter_text' => 0,
@@ -404,6 +405,7 @@
'alt' => '',
'prefix' => '',
'suffix' => '',
+ 'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
@@ -412,6 +414,9 @@
'strip_tags' => 0,
'html' => 0,
),
+ 'empty' => '',
+ 'hide_empty' => 0,
+ 'empty_zero' => 0,
'set_precision' => FALSE,
'precision' => 0,
'decimal' => '.',
@@ -419,15 +424,12 @@
'prefix' => '',
'suffix' => '',
'exclude' => 0,
- 'id' => 'np_views_page',
- 'table' => 'node',
- 'field' => 'np_views_page',
- 'override' => array(
- 'button' => 'Override',
- ),
+ 'id' => 'page_all',
+ 'table' => 'scan_hits',
+ 'field' => 'page_all',
'relationship' => 'none',
),
- 'np_views_widget_24' => array(
+ 'widget_today' => array(
'label' => 'Wid. Views (24hrs)',
'alter' => array(
'alter_text' => 0,
@@ -457,12 +459,12 @@
'prefix' => '',
'suffix' => '',
'exclude' => 0,
- 'id' => 'np_views_widget_24',
- 'table' => 'node',
- 'field' => 'np_views_widget_24',
+ 'id' => 'widget_today',
+ 'table' => 'scan_hits',
+ 'field' => 'widget_today',
'relationship' => 'none',
),
- 'np_views_widget' => array(
+ 'widget_all' => array(
'label' => 'Wid. Views (all)',
'alter' => array(
'alter_text' => 0,
@@ -473,6 +475,7 @@
'alt' => '',
'prefix' => '',
'suffix' => '',
+ 'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
@@ -481,6 +484,9 @@
'strip_tags' => 0,
'html' => 0,
),
+ 'empty' => '',
+ 'hide_empty' => 0,
+ 'empty_zero' => 0,
'set_precision' => FALSE,
'precision' => 0,
'decimal' => '.',
@@ -488,12 +494,9 @@
'prefix' => '',
'suffix' => '',
'exclude' => 0,
- 'id' => 'np_views_widget',
- 'table' => 'node',
- 'field' => 'np_views_widget',
- 'override' => array(
- 'button' => 'Override',
- ),
+ 'id' => 'widget_all',
+ 'table' => 'scan_hits',
+ 'field' => 'widget_all',
'relationship' => 'none',
),
'cid2' => array(
@@ -507,6 +510,7 @@
'alt' => '',
'prefix' => '',
'suffix' => '',
+ 'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
@@ -515,6 +519,9 @@
'strip_tags' => 0,
'html' => 0,
),
+ 'empty' => '',
+ 'hide_empty' => 0,
+ 'empty_zero' => 0,
'link_to_node' => 0,
'exclude' => 0,
'id' => 'cid2',
@@ -783,10 +790,10 @@
'name' => 'name',
'created' => 'created',
'velocity' => 'velocity',
- 'np_views_24' => 'np_views_24',
- 'np_views_page' => 'np_views_page',
- 'np_views_widget_24' => 'np_views_widget_24',
- 'np_views_widget' => 'np_views_widget',
+ 'page_today' => 'page_today',
+ 'page_all' => 'page_all',
+ 'widget_today' => 'widget_today',
+ 'widget_all' => 'widget_all',
'cid2' => 'cid2',
'value' => 'value',
'title_1' => 'title_1',
@@ -826,19 +833,19 @@
'sortable' => 1,
'separator' => '',
),
- 'np_views_24' => array(
+ 'page_today' => array(
'sortable' => 1,
'separator' => '',
),
- 'np_views_page' => array(
+ 'page_all' => array(
'sortable' => 1,
'separator' => '',
),
- 'np_views_widget_24' => array(
+ 'widget_today' => array(
'sortable' => 1,
'separator' => '',
),
- 'np_views_widget' => array(
+ 'widget_all' => array(
'sortable' => 1,
'separator' => '',
),
@@ -992,13 +999,15 @@
'changed' => 'changed',
'status' => 'status',
'difference' => 'difference',
+ 'archived' => 'archived',
'title' => 'title',
'name' => 'name',
'created' => 'created',
'velocity' => 'velocity',
- 'np_views_24' => 'np_views_24',
- 'np_views_page' => 'np_views_page',
- 'np_views_widget' => 'np_views_widget',
+ 'page_today' => 'page_today',
+ 'page_all' => 'page_all',
+ 'widget_today' => 'widget_today',
+ 'widget_all' => 'widget_all',
'cid2' => 'cid2',
'value' => 'value',
'title_1' => 'title_1',
@@ -1019,6 +1028,9 @@
'difference' => array(
'separator' => '',
),
+ 'archived' => array(
+ 'separator' => '',
+ ),
'title' => array(
'sortable' => 0,
'separator' => '',
@@ -1035,15 +1047,19 @@
'sortable' => 1,
'separator' => '',
),
- 'np_views_24' => array(
+ 'page_today' => array(
'sortable' => 0,
'separator' => '',
),
- 'np_views_page' => array(
+ 'page_all' => array(
'sortable' => 1,
'separator' => '',
),
- 'np_views_widget' => array(
+ 'widget_today' => array(
+ 'sortable' => 0,
+ 'separator' => '',
+ ),
+ 'widget_all' => array(
'sortable' => 1,
'separator' => '',
),
@@ -1063,12 +1079,13 @@
'default' => 'created',
'execution_type' => '2',
'display_type' => '1',
+ 'hide_select_all' => 0,
'skip_confirmation' => 0,
'display_result' => 1,
'merge_single_action' => 1,
'selected_operations' => array(
- '0' => 'views_bulk_operations_delete_node_action',
- '1' => 'np_scan_set_offline',
+ 'views_bulk_operations_delete_node_action' => 'views_bulk_operations_delete_node_action',
+ 'np_scan_set_offline' => 'np_scan_set_offline',
),
));
$handler->override_option('path', 'admin/np/scan_admin');
Index: www/sites/all/modules/custom/np_scan/np_scan.module
===================================================================
--- www/sites/all/modules/custom/np_scan/np_scan.module (revision 34382)
+++ www/sites/all/modules/custom/np_scan/np_scan.module (working copy)
@@ -436,6 +436,36 @@
/* Backfilling. Wait until next run. */
}
}
+
+ // Mini-worker to update the page views for this minute.
+ require_once(drupal_get_path('module', 'np_potpourri') .'/BeanStalk.class.php');
+ $beanstalk = BeanStalk::open(array(
+ 'servers' => array( variable_get('np_scan_beanstalk_host', '67.220.204.51:11300') ),
+ 'select' => 'random peek',
+ 'auto_unyaml' => false,
+ ));
+
+ $beanstalk->watch('hit-logger');
+ scan_api_set_active_shard('misc');
+ while ($job = $beanstalk->reserve_with_timeout(0)) {
+ $data = explode('|', $job->get());
+ switch ($data[1]) {
+ case 'widget':
+ $query = 'UPDATE {scan_hits} SET widget_today = widget_today + 1, widget_all = widget_all + 1, widget_last = %d WHERE nid = %d';
+ break;
+ case 'page':
+ $query = 'UPDATE {scan_hits} SET page_today = page_today + 1, page_all = page_all + 1, page_last = %d WHERE nid = %d';
+ break;
+ }
+ db_query($query, $data[2], $data[0]);
+ if (db_affected_rows()) {
+ $job->delete();
+ }
+ else {
+ // Hmm, update didn't work. Let's try again in a minute...
+ $job->release(1024, 60);
+ }
+ }
scan_api_set_active_shard();
}
@@ -768,6 +798,9 @@
$scan_settings->use_globals = NP_SCAN_USE_GLOBAL_EXPLETIVES | NP_SCAN_USE_GLOBAL_USERS | NP_SCAN_USE_GLOBAL_URLS;
drupal_write_record('scan_settings', $scan_settings);
+ // Add the hit counter / denormalized data for sorting on mysql side.
+ db_query('INSERT INTO {scan_hits} (nid, client_id, status, created) VALUES (%d, %d, %d, %d)', $node->nid, $node->og_groups[0], $scan_settings->status, $node->created);
+
if (isset($node->locations)) {
foreach ($node->locations as $location) {
$location->scan_id = $scan->scan_id;
@@ -916,6 +949,7 @@
np_scan_queue_delete($row->scan_id);
}
db_query("DELETE FROM {scan} WHERE nid = %d", $node->nid);
+ db_query("DELETE FROM {scan_hits} WHERE nid = %d", $node->nid);
db_query("DELETE FROM {scan_settings} WHERE nid = %d", $node->nid);
db_query("DELETE FROM {scan_destination} WHERE nid = %d", $node->nid);
np_scan_reload_workers('scan');
@@ -1936,6 +1970,8 @@
function np_scan_change_status($nid, $new_status) {
scan_api_set_active_shard('misc');
$result = db_query('UPDATE {scan_settings} SET status = %d WHERE nid = %d', $new_status, $nid);
+ // Denormalize scan status to the scan_hits table.
+ db_query('UPDATE {scan_hits} SET status = %d WHERE nid = %d', $new_status, $nid);
$scan_id = db_result(db_query_range("
SELECT s.scan_id
FROM {scan_settings} ss
Index: www/sites/all/modules/custom/np_scan/np_scan.archive.inc
===================================================================
--- www/sites/all/modules/custom/np_scan/np_scan.archive.inc (revision 34382)
+++ www/sites/all/modules/custom/np_scan/np_scan.archive.inc (working copy)
@@ -13,7 +13,7 @@
if (!empty($scan)) {
$total_posts = db_result(db_query('SELECT COUNT(*) FROM {scan_items} WHERE scan_id = %d', $scan_id));
- $total_views = db_result(db_query('SELECT np_views_page + np_views_widget FROM {node} WHERE nid = %d', $scan->nid));
+ $total_views = db_result(db_query('SELECT widget_all + page_all FROM {scan_hits} WHERE nid = %d', $scan->nid));
$recommendations = db_result(db_query_range("SELECT value FROM {votingapi_cache} WHERE content_type = 'scan' AND content_id = %d AND function = 'sum'", $scan->nid, 0, 1));
$recommended_posts = db_result(db_query('SELECT COUNT(*) FROM {scan_items} WHERE scan_id = %d AND recommend > 0', $scan_id));
Index: www/sites/all/modules/custom/np_scan_export/np_scan_export.module
===================================================================
--- www/sites/all/modules/custom/np_scan_export/np_scan_export.module (revision 34382)
+++ www/sites/all/modules/custom/np_scan_export/np_scan_export.module (working copy)
@@ -53,13 +53,7 @@
foreach($groups as $gid => $group) {
// Select all the views for scans in that group
// that were viewed in the last 24 hrs.
- $result = db_query("
- SELECT n.nid, n.title, n.created, n.np_views_page, n.np_views_24, n.np_views_widget, n.np_views_widget_24
- FROM {node} n
- LEFT JOIN {og_ancestry} oga ON n.nid = oga.nid
- INNER JOIN {node} noga ON oga.group_nid = noga.nid
- WHERE oga.group_nid = %d AND
- (n.np_views_24 > 0 OR n.np_views_widget_24 > 0)", $gid);
+ $result = db_query('SELECT h.* FROM {scan_hits} h INNER JOIN {og_ancestry} o ON h.nid = o.nid WHERE o.group_nid = %d AND (h.widget_today > 0 OR h.page_today > 0)', $gid);
$csv = '';
while ($scan = db_fetch_object($result)) {
@@ -67,10 +61,10 @@
array(
$scan->title,
url("node/$scan->nid/edit", array('absolute' => TRUE)),
- $scan->np_views_page,
- $scan->np_views_24,
- $scan->np_views_widget,
- $scan->np_views_widget_24,
+ $scan->page_all,
+ $scan->page_today,
+ $scan->widget_all,
+ $scan->widget_today,
)
);
}
Index: www/sites/all/modules/custom/np_potpourri/np_potpourri.beanstalk.inc
===================================================================
--- www/sites/all/modules/custom/np_potpourri/np_potpourri.beanstalk.inc (revision 34382)
+++ www/sites/all/modules/custom/np_potpourri/np_potpourri.beanstalk.inc (working copy)
@@ -18,6 +18,7 @@
$searchapi_stats = array();
$statworker_stats = array();
$delete_stats = array();
+ $hit_stats = array();
$default_stats = array();
$stats = array();
@@ -42,6 +43,9 @@
$beanstalk->stats_tube($prefix . "delete", $delete_stats);
$output .= t('
Scan Deletion Queue stats
');
$output .= theme('table', array(), _np_potpourri_beanstalk_format($delete_stats));
+ $beanstalk->stats_tube($prefix . "hit-logger", $hit_stats);
+ $output .= t('Scan Hit Logger Queue stats
');
+ $output .= theme('table', array(), _np_potpourri_beanstalk_format($hit_stats));
$beanstalk->stats_tube($prefix . "default", $default_stats);
$output .= t('Default Queue stats
');
$output .= theme('table', array(), _np_potpourri_beanstalk_format($default_stats));
Index: www/sites/all/modules/custom/np_scan_recommend/np_scan_recommend.info
===================================================================
--- www/sites/all/modules/custom/np_scan_recommend/np_scan_recommend.info (revision 34382)
+++ www/sites/all/modules/custom/np_scan_recommend/np_scan_recommend.info (working copy)
@@ -3,3 +3,4 @@
description = Recommend scans and scan items, and possibly other scan related voting.
package = NP
core = 6.x
+dependencies[] = np_log
Index: www/sites/all/modules/custom/np_scan_recommend/np_scan_recommend.module
===================================================================
--- www/sites/all/modules/custom/np_scan_recommend/np_scan_recommend.module (revision 34382)
+++ www/sites/all/modules/custom/np_scan_recommend/np_scan_recommend.module (working copy)
@@ -218,7 +218,8 @@
elseif ($content_type == 'scan') {
foreach ($cached as $cache) {
if ($cache['function'] == 'sum' && $cache['tag'] == NP_SCAN_RECOMMEND_SCAN && $cache['value_type'] =='points') {
- db_query('UPDATE {node} SET recommend = %d WHERE nid = %d', $cache['value'], $content_id);
+ // Table is maintained by np_log.
+ db_query('UPDATE {scan_hits} SET recommend = %d WHERE nid = %d', $cache['value'], $content_id);
}
}
}
Index: www/sites/all/modules/custom/np_log/np_log.module
===================================================================
--- www/sites/all/modules/custom/np_log/np_log.module (revision 34382)
+++ www/sites/all/modules/custom/np_log/np_log.module (working copy)
@@ -11,3 +11,39 @@
function np_log_views_api() {
return array('api' => 2.0);
}
+
+/**
+ * Implementation of hook_cron().
+ * On-the-hour cron hook to roll over daily hit counting at the proper time.
+ */
+function np_log_cron() {
+ $timestamp = time();
+ $tz = date_default_timezone_get();
+
+ $zones = db_query('SELECT DISTINCT field_timezone_value AS tz FROM {content_type_group}');
+ while ($zone = db_fetch_object($zones)) {
+ $key = 'cleanup:' . $zone->tz;
+ date_default_timezone_set($zone->tz);
+ // If we have changed days in the timezone we are processing...
+ if (date('d', variable_get($key, 0)) != date('d', $timestamp)) {
+ variable_set($key, $time);
+ // h: Hit counter table.
+ // n: Group nodes. Used to ensure we're only using the newest revision of the group node.
+ // g: Group settings. Used to match on timezone.
+ // o: Ancestry. Used to determine what nodes the matched groups have.
+ db_query("UPDATE {scan_hits} h,
+ {node} n,
+ {content_type_group} g,
+ {og_ancestry} o
+ SET widget_today = 0, page_today = 0
+ WHERE n.nid = o.group_nid
+ AND n.vid = g.vid
+ AND h.nid = o.nid
+ AND g.field_timezone_value = '%s'", $zone->tz);
+ $count = db_affected_rows();
+ watchdog('np_log', 'Reset daily counts on %count nodes in timezone %tz', array('%count' => $count, '%tz' => $zone->tz));
+ }
+ }
+ // Restore original timezone.
+ date_default_timezone_set($tz);
+}
Index: www/sites/all/modules/custom/np_log/np_log.views.inc
===================================================================
--- www/sites/all/modules/custom/np_log/np_log.views.inc (revision 34382)
+++ www/sites/all/modules/custom/np_log/np_log.views.inc (working copy)
@@ -1,11 +1,18 @@
t('Page Views'),
- 'help' => t('All page views for scan.'),
- 'group' => t('Scan'),
+ $data['scan_hits']['table']['join'] = array(
+ 'node' => array(
+ 'left_field' => 'nid',
+ 'field' => 'nid',
+ ),
+ );
+
+ $data['scan_hits']['widget_today'] = array(
+ 'title' => t('Widget Views: Today'),
+ 'help' => t('The number of widget views in the last 24 hours.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
@@ -15,10 +22,9 @@
),
);
- $data['node']['np_views_widget'] = array(
+ $data['scan_hits']['widget_all'] = array(
'title' => t('Widget Views: All'),
'help' => t('All widget views for scan.'),
- 'group' => t('Scan'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
@@ -28,11 +34,22 @@
),
);
- $data['node']['np_views_widget_24'] = array(
- 'title' => t('Widget Views: 24h'),
- 'help' => t('The number of widget views in the last 24 hours.'),
- 'group' => t('Scan'),
+ $data['scan_hits']['widget_last'] = array(
+ 'title' => t('Widget Views: Last View Timestamp'),
+ 'help' => t('The timestamp of the last widget view.'),
'field' => array(
+ 'handler' => 'views_handler_field_date',
+ 'click sortable' => TRUE,
+ ),
+ 'sort' => array(
+ 'handler' => 'views_handler_sort_date',
+ ),
+ );
+
+ $data['scan_hits']['page_today'] = array(
+ 'title' => t('Page Views: Today'),
+ 'help' => t('The number of page views in the last 24 hours'),
+ 'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
@@ -41,9 +58,9 @@
),
);
- $data['node']['np_views_24'] = array(
- 'title' => t('24 hrs views'),
- 'help' => t('The number of views in the last 24 hours'),
+ $data['scan_hits']['page_all'] = array(
+ 'title' => t('Page Views: All'),
+ 'help' => t('All page views for scan.'),
'group' => t('Scan'),
'field' => array(
'handler' => 'views_handler_field_numeric',
@@ -54,5 +71,17 @@
),
);
+ $data['scan_hits']['page_last'] = array(
+ 'title' => t('Page Views: Last View Timestamp'),
+ 'help' => t('The timestamp of the last page view.'),
+ 'field' => array(
+ 'handler' => 'views_handler_field_date',
+ 'click sortable' => TRUE,
+ ),
+ 'sort' => array(
+ 'handler' => 'views_handler_sort_date',
+ ),
+ );
+
return $data;
}
Index: www/sites/all/modules/custom/np_log/np_log.install
===================================================================
--- www/sites/all/modules/custom/np_log/np_log.install (revision 0)
+++ www/sites/all/modules/custom/np_log/np_log.install (revision 0)
@@ -0,0 +1,112 @@
+ t('Stores daily and all-time tallies for widget and page views.'),
+ 'fields' => array(
+ 'nid' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'description' => t('The nid being tracked.'),
+ ),
+ 'client_id' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => t('Denormalized og nid of client.'),
+ ),
+ 'created' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => t('Denormalized node created time.'),
+ ),
+ 'status' => array(
+ 'type' => 'int',
+ 'size' => 'tiny',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => t('Denormalized scan status from {scan_settings}.'),
+ ),
+ 'recommend' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => t('Number of recommendations (maintained by np_scan_recommend.module)'),
+ ),
+ 'widget_today' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => t('Daily widget views. Reset once a day.'),
+ ),
+ 'widget_all' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => t('All time widget views.'),
+ ),
+ 'widget_last' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => t('Unix timestamp of last widget view.'),
+ ),
+ 'page_today' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => t('Daily page hits. Reset once a day.'),
+ ),
+ 'page_all' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => t('All time page hits.'),
+ ),
+ 'page_last' => array(
+ 'type' => 'int',
+ 'unsigned' => TRUE,
+ 'not null' => TRUE,
+ 'default' => 0,
+ 'description' => t('Unix timestamp of last page hit.'),
+ ),
+ ),
+ 'primary key' => array('nid'),
+ 'indexes' => array(
+ 'widget_today_idx' => array('widget_today'),
+ 'widget_all_idx' => array('widget_all'),
+ 'widget_last_idx' => array('widget_last'),
+ 'page_today_idx' => array('page_today'),
+ 'page_all_idx' => array('page_all'),
+ 'page_last_idx' => array('page_last'),
+ 'recommend_idx' => array('recommend'),
+ ),
+ );
+ return $schema;
+}
Index: www/np_log.php
===================================================================
--- www/np_log.php (revision 34382)
+++ www/np_log.php (working copy)
@@ -1,32 +1,30 @@
add($full_key, 1, FALSE, $expire) ? 1 : $mc->increment($full_key);
- if ($new_value && ($type == 'page' || $new_value % 5 == 0)) {
- drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
- db_set_active('scan');
- if ($type == 'page') {
- db_query("UPDATE {node} SET np_views_24 = np_views_24 + 1, np_views_page = np_views_page + 1 WHERE nid = %d", $nid);
- }
- else {
- db_query("UPDATE {node} SET np_views_widget_24 = %d, np_views_widget = np_views_widget + 5, np_views_widget_last = UNIX_TIMESTAMP() WHERE nid = %d", $new_value, $nid);
- }
- db_set_active();
+ $type = ($_GET['type'] == 'widget') ? 'widget' : 'page';
+ $timestamp = $_SERVER["REQUEST_TIME"];
+ //@todo This is the best place to collect the IP address of the client.
+ // We can find the proxy list in the server variable
+ // $_SERVER["HTTP_X_FORWARDED_FOR"].
+
+ if ($nid > 0) {
+ $beanstalk = BeanStalk::open(array(
+ 'servers' => array( variable_get('np_scan_beanstalk_host', '67.220.204.51:11300') ),
+ 'select' => 'random peek',
+ 'auto_unyaml' => false,
+ ));
+ $job = array(
+ $nid,
+ $type,
+ $timestamp,
+ );
+
+ $beanstalk->put(1024, 0, 120, implode('|', $job), 'hit-logger');
}
}
header('Content-type: image/gif');
Index: view/sites/all/modules/scan_api/scan_api.module
===================================================================
--- view/sites/all/modules/scan_api/scan_api.module (revision 34382)
+++ view/sites/all/modules/scan_api/scan_api.module (working copy)
@@ -113,7 +113,7 @@
'access callback' => TRUE,
'type' => MENU_CALLBACK,
'page callback' => 'scan_top_scan',
- 'page arguments' => array('np_views_page'),
+ 'page arguments' => array('page_all'),
);
$items['scan.top.scan.recent'] = array(
'access callback' => TRUE,
@@ -1532,21 +1532,22 @@
// scan_nids
$return = array();
$scan_ids = array();
- // $order IN velocity, np_views_page, created, recommend
- if (in_array($order, array('np_views_page', 'created' ,'recommend'))) {
- $params = _scan_get_client_nids(array(intval($client_id)));
- if ($params) {
+ // $order IN velocity, page_all, created, recommend
+ if (in_array($order, array('page_all', 'created' ,'recommend'))) {
+ $client_id = intval($client_id);
+ if ($client_id) {
// get the basic data ordered
scan_api_set_active_shard('misc');
$rs = db_query_range("
- SELECT s.nid, s.scan_id, s.and_words, s.or_words, nr.title, n.created, n.np_views_page as pageviews, n.recommend
- FROM {node} n
- INNER JOIN {node_revisions} nr ON n.vid = nr.vid
- INNER JOIN {scan_settings} ss ON ss.nid = n.nid
+ SELECT s.nid, s.scan_id, s.and_words, s.or_words, nr.title, h.created, h.page_all AS pageviews, h.recommend
+ FROM {scan_hits} h
+ INNER JOIN {scan_settings} ss ON ss.nid = h.nid
INNER JOIN {scan} s ON s.vid = ss.active_vid
- WHERE n.nid IN (" . implode(',', array_fill(0, count($params), '%d')) . ")
- ORDER BY n." . $order . " DESC
- ", $params, 0, $count);
+ INNER JOIN {node_revisions} nr ON nr.vid = ss.active_vid
+ WHERE h.client_id = %d
+ AND h.status = 1
+ ORDER BY h." . $order . " DESC
+ ", $client_id, 0, $count);
while ($row = db_fetch_array($rs)) {
$row['created'] = gmdate('c', $row['created']);
$row['general'] = 0;
@@ -1618,11 +1619,12 @@
// fill up with basic info
scan_api_set_active_shard('misc');
$rs = db_query("
- SELECT s.scan_id, s.nid, s.and_words, s.or_words, nr.title, n.created, n.np_views_page as pageviews, n.recommend
+ SELECT s.scan_id, s.nid, s.and_words, s.or_words, nr.title, h.created, h.page_all as pageviews, h.recommend
FROM {scan} s
INNER JOIN {scan_settings} ss ON s.vid = ss.active_vid
INNER JOIN {node_revisions} nr ON s.vid = nr.vid
INNER JOIN {node} n ON s.nid = n.nid
+ INNER JOIN {scan_hits} h ON h.nid = n.nid
WHERE s.scan_id IN (" . $scan_id_placeholders . ")
", $scan_ids);
while ($row = db_fetch_array($rs)) {
@@ -2361,36 +2363,6 @@
return $scan_ids;
}
-/**
- * Helper function to return scan_ids belonging to given client ids
- */
-function _scan_get_client_nids($client_ids) {
- $client_nids = array();
-
- if (is_array($client_ids) && $client_ids) {
- $client_id_placeholders = implode(',', array_fill(0, count($client_ids), '%d'));
- scan_api_set_active_shard('drupal', 'og_ancestry');
- $result = db_query("
- SELECT o.nid
- FROM {og_ancestry} o
- INNER JOIN {scan_settings} ss ON ss.nid = o.nid AND ss.status = 1
- WHERE o.group_nid IN (" . $client_id_placeholders . ")
- ", $client_ids);
- $client_nids = array();
- while ($row = db_fetch_array($result)) {
- $client_nids[] = $row['nid'];
- }
-
- if (!empty($client_nids)) {
- arsort($client_nids);
- $client_nids = array_slice($client_nids, 0, 50);
- }
- scan_api_set_active_shard();
- }
-
- return $client_nids;
-}
-
function _scan_api_filter_hashtags ($item) {
return substr($item, 0, 1) == '#';
}
Index: view/np_log.php
===================================================================
--- view/np_log.php (revision 34382)
+++ view/np_log.php (working copy)
@@ -1,32 +1,30 @@
add($full_key, 1, FALSE, $expire) ? 1 : $mc->increment($full_key);
- if ($new_value && ($type == 'page' || $new_value % 5 == 0)) {
- drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
- db_set_active('scan');
- if ($type == 'page') {
- db_query("UPDATE {node} SET np_views_24 = np_views_24 + 1, np_views_page = np_views_page + 1 WHERE nid = %d", $nid);
- }
- else {
- db_query("UPDATE {node} SET np_views_widget_24 = %d, np_views_widget = np_views_widget + 5, np_views_widget_last = UNIX_TIMESTAMP() WHERE nid = %d", $new_value, $nid);
- }
- db_set_active();
+ $type = ($_GET['type'] == 'widget') ? 'widget' : 'page';
+ $timestamp = $_SERVER["REQUEST_TIME"];
+ //@todo This is the best place to collect the IP address of the client.
+ // We can find the proxy list in the server variable
+ // $_SERVER["HTTP_X_FORWARDED_FOR"].
+
+ if ($nid > 0) {
+ $beanstalk = BeanStalk::open(array(
+ 'servers' => array( variable_get('np_scan_beanstalk_host', '67.220.204.51:11300') ),
+ 'select' => 'random peek',
+ 'auto_unyaml' => false,
+ ));
+ $job = array(
+ $nid,
+ $type,
+ $timestamp,
+ );
+
+ $beanstalk->put(1024, 0, 120, implode('|', $job), 'hit-logger');
}
}
header('Content-type: image/gif');