Index: www/sites/all/modules/custom/scan_api/scan_api.module =================================================================== --- www/sites/all/modules/custom/scan_api/scan_api.module (revision 34204) +++ www/sites/all/modules/custom/scan_api/scan_api.module (working copy) @@ -311,7 +311,17 @@ array_push($params, $scan_id, $max_age); scan_api_set_active_shard('posts'); - if ($total = db_result(db_query("SELECT COUNT(*) FROM {scan_items} si " . $extra_join . " WHERE si.scan_id = %d AND si.created >= DATE_SUB(NOW(), INTERVAL %d SECOND)" . $extra_where, $params))) { + + $total = dmemcache_get("sgi:$scan_id", 'pager'); + // Hide this query behind memcache because it sucks. + if ($total === FALSE) { + $total = db_result(db_query("SELECT COUNT(*) FROM {scan_items} si " . $extra_join . " WHERE si.scan_id = %d AND si.created >= DATE_SUB(NOW(), INTERVAL %d SECOND)" . $extra_where, $params)); + if ($total > 1000) { + // This scan is nontrivial, don't constantly recalculate the item count. + dmemcache_set("sgi:$scan_id", $total, time() + 120, 'pager'); + } + } + if ($total) { do { $items = array(); scan_api_set_active_shard('posts'); @@ -574,7 +584,17 @@ array_push($params, $scan_id, $max_age); scan_api_set_active_shard('posts'); - if ($total = db_result(db_query("SELECT COUNT(*) FROM {scan_items} si " . $extra_join . " WHERE si.scan_id = %d AND si.created >= DATE_SUB(NOW(), INTERVAL %d SECOND)" . $extra_where, $params))) { + + $total = dmemcache_get("sti:$scan_id", 'pager'); + // Hide this query behind memcache because it sucks. + if ($total === FALSE) { + $total = db_result(db_query("SELECT COUNT(*) FROM {scan_items} si " . $extra_join . " WHERE si.scan_id = %d AND si.created >= DATE_SUB(NOW(), INTERVAL %d SECOND)" . $extra_where, $params)); + if ($total > 1000) { + // This scan is nontrivial, don't constantly recalculate the item count. + dmemcache_set("sti:$scan_id", $total, time() + 120, 'pager'); + } + } + if ($total) { do { $items = array(); scan_api_set_active_shard('posts'); Index: view/sites/all/modules/scan_api/scan_api.module =================================================================== --- view/sites/all/modules/scan_api/scan_api.module (revision 34204) +++ view/sites/all/modules/scan_api/scan_api.module (working copy) @@ -311,7 +311,17 @@ array_push($params, $scan_id, $max_age); scan_api_set_active_shard('posts'); - if ($total = db_result(db_query("SELECT COUNT(*) FROM {scan_items} si " . $extra_join . " WHERE si.scan_id = %d AND si.created >= DATE_SUB(NOW(), INTERVAL %d SECOND)" . $extra_where, $params))) { + + $total = dmemcache_get("sgi:$scan_id", 'pager'); + // Hide this query behind memcache because it sucks. + if ($total === FALSE) { + $total = db_result(db_query("SELECT COUNT(*) FROM {scan_items} si " . $extra_join . " WHERE si.scan_id = %d AND si.created >= DATE_SUB(NOW(), INTERVAL %d SECOND)" . $extra_where, $params)); + if ($total > 1000) { + // This scan is nontrivial, don't constantly recalculate the item count. + dmemcache_set("sgi:$scan_id", $total, time() + 120, 'pager'); + } + } + if ($total) { do { $items = array(); scan_api_set_active_shard('posts'); @@ -574,7 +584,17 @@ array_push($params, $scan_id, $max_age); scan_api_set_active_shard('posts'); - if ($total = db_result(db_query("SELECT COUNT(*) FROM {scan_items} si " . $extra_join . " WHERE si.scan_id = %d AND si.created >= DATE_SUB(NOW(), INTERVAL %d SECOND)" . $extra_where, $params))) { + + $total = dmemcache_get("sti:$scan_id", 'pager'); + // Hide this query behind memcache because it sucks. + if ($total === FALSE) { + $total = db_result(db_query("SELECT COUNT(*) FROM {scan_items} si " . $extra_join . " WHERE si.scan_id = %d AND si.created >= DATE_SUB(NOW(), INTERVAL %d SECOND)" . $extra_where, $params)); + if ($total > 1000) { + // This scan is nontrivial, don't constantly recalculate the item count. + dmemcache_set("sti:$scan_id", $total, time() + 120, 'pager'); + } + } + if ($total) { do { $items = array(); scan_api_set_active_shard('posts');