Small query fix for systems with large queue_log table

git-svn-id: svn://192.168.202.10@1594 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2011-01-24 16:47:05 +00:00
parent 7b3ad712ae
commit fa2b47558b
7 changed files with 25 additions and 14 deletions
+1 -1
View File
@@ -17,7 +17,7 @@
# ; 7. audio filename for invalid user id re-enter prompt, agent not available # ; 7. audio filename for invalid user id re-enter prompt, agent not available
# ; 8. number of retry attempts to enter a valid user ID # ; 8. number of retry attempts to enter a valid user ID
# ; this will only be enforced if "prompt for user ID" prompt is populated # ; this will only be enforced if "prompt for user ID" prompt is populated
# ; 7. in-group to send the call to if there is no valid agent, if none is # ; 9. in-group to send the call to if there is no valid agent, if none is
# ; defined, then the call will be directed to 's' exten # ; defined, then the call will be directed to 's' exten
# ; 10. audio filename before sending call to no-agent route # ; 10. audio filename before sending call to no-agent route
# ; 11. audio filename before sending call to no-agent route if agent active but # ; 11. audio filename before sending call to no-agent route if agent active but
+3 -1
View File
@@ -95,6 +95,7 @@
# 101117-1656 - Added accounting for DEAD agent calls when in available-only-tally dialing # 101117-1656 - Added accounting for DEAD agent calls when in available-only-tally dialing
# 101207-0713 - Added more info to Originate for rare VDAC issue # 101207-0713 - Added more info to Originate for rare VDAC issue
# 110103-1227 - Added queuemetrics_loginout NONE option # 110103-1227 - Added queuemetrics_loginout NONE option
# 110124-1134 - Small query fix for large queue_log tables
# #
@@ -1970,7 +1971,7 @@ while($one_day_interval > 0)
$RAWtime_logged_in=$TDtarget; $RAWtime_logged_in=$TDtarget;
if ($queuemetrics_loginout !~ /NONE/) if ($queuemetrics_loginout !~ /NONE/)
{ {
$stmtB = "SELECT time_id,data1 FROM queue_log where agent='Agent/$VALOuser[$logrun]' and verb IN('AGENTLOGIN','AGENTCALLBACKLOGIN') order by time_id desc limit 1;"; $stmtB = "SELECT time_id,data1 FROM queue_log where agent='Agent/$VALOuser[$logrun]' and verb IN('AGENTLOGIN','AGENTCALLBACKLOGIN') and time_id > $check_time order by time_id desc limit 1;";
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
$sthB->execute or die "executing: $stmtA ", $dbhB->errstr; $sthB->execute or die "executing: $stmtA ", $dbhB->errstr;
$sthBrows=$sthB->rows; $sthBrows=$sthB->rows;
@@ -2377,6 +2378,7 @@ sub get_time_now #get the current date and time and epoch for logging call lengt
$LOCAL_GMT_OFF = $SERVER_GMT; $LOCAL_GMT_OFF = $SERVER_GMT;
$LOCAL_GMT_OFF_STD = $SERVER_GMT; $LOCAL_GMT_OFF_STD = $SERVER_GMT;
if ($isdst) {$LOCAL_GMT_OFF++;} if ($isdst) {$LOCAL_GMT_OFF++;}
$check_time = ($secX - 86400);
$GMT_now = ($secX - ($LOCAL_GMT_OFF * 3600)); $GMT_now = ($secX - ($LOCAL_GMT_OFF * 3600));
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($GMT_now); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($GMT_now);
+3 -1
View File
@@ -37,6 +37,7 @@
# 100622-0917 - Added start_call_url function for remote agents, this launches a separate child script # 100622-0917 - Added start_call_url function for remote agents, this launches a separate child script
# 101108-0032 - Added ADDMEMBER queue_log code # 101108-0032 - Added ADDMEMBER queue_log code
# 110103-1230 - Added queuemetrics_loginout NONE option # 110103-1230 - Added queuemetrics_loginout NONE option
# 110124-1134 - Small query fix for large queue_log tables
# #
### begin parsing run-time options ### ### begin parsing run-time options ###
@@ -797,7 +798,7 @@ while($one_day_interval > 0)
$stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$secX',call_id='NONE',queue='NONE',agent='Agent/$VD_user[$z]',verb='PAUSEALL',serverid='$queuemetrics_log_id';"; $stmtB = "INSERT INTO queue_log SET partition='P01',time_id='$secX',call_id='NONE',queue='NONE',agent='Agent/$VD_user[$z]',verb='PAUSEALL',serverid='$queuemetrics_log_id';";
$Baffected_rows = $dbhB->do($stmtB); $Baffected_rows = $dbhB->do($stmtB);
$stmtB = "SELECT time_id,data1 FROM queue_log where agent='Agent/$VD_user[$z]' and verb IN('AGENTLOGIN','AGENTCALLBACKLOGIN') order by time_id desc limit 1;"; $stmtB = "SELECT time_id,data1 FROM queue_log where agent='Agent/$VD_user[$z]' and verb IN('AGENTLOGIN','AGENTCALLBACKLOGIN') and time_id > $check_time order by time_id desc limit 1;";
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr; $sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
$sthBrows=$sthB->rows; $sthBrows=$sthB->rows;
@@ -986,6 +987,7 @@ sub get_time_now #get the current date and time and epoch for logging call lengt
$LOCAL_GMT_OFF = $SERVER_GMT; $LOCAL_GMT_OFF = $SERVER_GMT;
$LOCAL_GMT_OFF_STD = $SERVER_GMT; $LOCAL_GMT_OFF_STD = $SERVER_GMT;
if ($isdst) {$LOCAL_GMT_OFF++;} if ($isdst) {$LOCAL_GMT_OFF++;}
$check_time = ($secX - 86400);
$GMT_now = ($secX - ($LOCAL_GMT_OFF * 3600)); $GMT_now = ($secX - ($LOCAL_GMT_OFF * 3600));
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($GMT_now); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($GMT_now);
+4 -3
View File
@@ -10,7 +10,7 @@
# #
# This program only needs to be run by one server # This program only needs to be run by one server
# #
# Copyright (C) 2010 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2 # Copyright (C) 2011 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# #
# CHANGES # CHANGES
# 60711-0945 - Changed to DBI by Marin Blu # 60711-0945 - Changed to DBI by Marin Blu
@@ -27,6 +27,7 @@
# 100309-0555 - Added queuemetrics_loginout option # 100309-0555 - Added queuemetrics_loginout option
# 100327-0926 - Added validation of four agent "sec" fields # 100327-0926 - Added validation of four agent "sec" fields
# 100331-0310 - Added one-day-ago and only-fix-old-lagged options, fixed validation process # 100331-0310 - Added one-day-ago and only-fix-old-lagged options, fixed validation process
# 110124-1134 - Small query fix for large queue_log tables
# #
# constants # constants
@@ -1561,7 +1562,7 @@ if ($enable_queuemetrics_logging > 0)
####################################################################### #######################################################################
##### grab all queue_log entries with more than one COMPLETE verb to clean up ##### grab all queue_log entries with more than one COMPLETE verb to clean up
$stmtB = "SELECT call_id, count(*) FROM queue_log WHERE verb IN('COMPLETEAGENT','COMPLETECALLER','TRANSFER') and serverid='$queuemetrics_log_id' GROUP BY call_id HAVING count(*)>1 ORDER BY count(*) DESC;"; $stmtB = "SELECT call_id, count(*) FROM queue_log WHERE verb IN('COMPLETEAGENT','COMPLETECALLER','TRANSFER') and serverid='$queuemetrics_log_id' $QM_SQL_time_H GROUP BY call_id HAVING count(*)>1 ORDER BY count(*) DESC;";
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr; $sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
$XC_records=$sthB->rows; $XC_records=$sthB->rows;
@@ -1589,7 +1590,7 @@ if ($enable_queuemetrics_logging > 0)
########################################################################## ##########################################################################
##### grab all queue_log COMPLETEAGENT entries with negative call time to clean up ##### grab all queue_log COMPLETEAGENT entries with negative call time to clean up
$stmtB = "SELECT call_id, time_id FROM queue_log WHERE verb IN('COMPLETEAGENT') and data2 < '0' and serverid='$queuemetrics_log_id';"; $stmtB = "SELECT call_id, time_id FROM queue_log WHERE verb IN('COMPLETEAGENT') and data2 < '0' and serverid='$queuemetrics_log_id' $QM_SQL_time_H;";
$sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr; $sthB = $dbhB->prepare($stmtB) or die "preparing: ",$dbhB->errstr;
$sthB->execute or die "executing: $stmtB ", $dbhB->errstr; $sthB->execute or die "executing: $stmtB ", $dbhB->errstr;
$XN_records=$sthB->rows; $XN_records=$sthB->rows;
+5 -3
View File
@@ -266,10 +266,11 @@
# 101128-0108 - Added list override for webforms # 101128-0108 - Added list override for webforms
# 101208-0414 - Fixed Call Log dial bug (issue 393) # 101208-0414 - Fixed Call Log dial bug (issue 393)
# 110103-1343 - Added queuemetrics_loginout NONE option # 110103-1343 - Added queuemetrics_loginout NONE option
# 110124-1134 - Small query fix for large queue_log tables
# #
$version = '2.4-172'; $version = '2.4-173';
$build = '110103-1343'; $build = '110124-1134';
$mel=1; # Mysql Error Log enabled = 1 $mel=1; # Mysql Error Log enabled = 1
$mysql_log_count=365; $mysql_log_count=365;
$one_mysql_log=0; $one_mysql_log=0;
@@ -476,6 +477,7 @@ $MT[0]='';
$agents='@agents'; $agents='@agents';
$US='_'; $US='_';
while (strlen($CIDdate) > 9) {$CIDdate = substr("$CIDdate", 1);} while (strlen($CIDdate) > 9) {$CIDdate = substr("$CIDdate", 1);}
$check_time = ($StarTtime - 86400);
##### Hangup Cause Dictionary ##### ##### Hangup Cause Dictionary #####
$hangup_cause_dictionary = array( $hangup_cause_dictionary = array(
@@ -5401,7 +5403,7 @@ if ($ACTION == 'userLOGout')
# $affected_rows = mysql_affected_rows($linkB); # $affected_rows = mysql_affected_rows($linkB);
$logintime=0; $logintime=0;
$stmt = "SELECT time_id,data1 FROM queue_log where agent='Agent/$user' and verb IN('AGENTLOGIN','AGENTCALLBACKLOGIN') order by time_id desc limit 1;"; $stmt = "SELECT time_id,data1 FROM queue_log where agent='Agent/$user' and verb IN('AGENTLOGIN','AGENTCALLBACKLOGIN') and time_id > $check_time order by time_id desc limit 1;";
$rslt=mysql_query($stmt, $linkB); $rslt=mysql_query($stmt, $linkB);
if ($mel > 0) {mysql_error_logging($NOW_TIME,$linkB,$mel,$stmt,'00139',$user,$server_ip,$session_name,$one_mysql_log);} if ($mel > 0) {mysql_error_logging($NOW_TIME,$linkB,$mel,$stmt,'00139',$user,$server_ip,$session_name,$one_mysql_log);}
if ($DB) {echo "$stmt\n";} if ($DB) {echo "$stmt\n";}
+5 -3
View File
@@ -2631,12 +2631,13 @@ else
# 101227-1320 - Added dialplan off toggle options # 101227-1320 - Added dialplan off toggle options
# 110103-1135 - Added queuemetrics_dispo_pause and lead_order_randomize features # 110103-1135 - Added queuemetrics_dispo_pause and lead_order_randomize features
# 110111-1305 - Added sort by list name for list listings in list section and campaign screens # 110111-1305 - Added sort by list name for list listings in list section and campaign screens
# 110124-1134 - Small query fix for large queue_log tables
# #
# make sure you have added a user to the vicidial_users MySQL table with at least user_level 8 to access this page the first time # make sure you have added a user to the vicidial_users MySQL table with at least user_level 8 to access this page the first time
$admin_version = '2.4-296'; $admin_version = '2.4-297';
$build = '110111-1305'; $build = '110124-1134';
$STARTtime = date("U"); $STARTtime = date("U");
$SQLdate = date("Y-m-d H:i:s"); $SQLdate = date("Y-m-d H:i:s");
@@ -2647,6 +2648,7 @@ $active_lists=0;
$inactive_lists=0; $inactive_lists=0;
$modify_refresh_set=0; $modify_refresh_set=0;
$modify_footer_refresh=0; $modify_footer_refresh=0;
$check_time = ($STARTtime - 86400);
$month_old = mktime(0, 0, 0, date("m")-1, date("d"), date("Y")); $month_old = mktime(0, 0, 0, date("m")-1, date("d"), date("Y"));
$past_month_date = date("Y-m-d H:i:s",$month_old); $past_month_date = date("Y-m-d H:i:s",$month_old);
@@ -16549,7 +16551,7 @@ if ($ADD==62)
$agent_logged_in=''; $agent_logged_in='';
$time_logged_in='0'; $time_logged_in='0';
$stmtB = "SELECT agent,time_id,data1 FROM queue_log where agent='Agent/$VLA_user[$k]' and verb IN('AGENTLOGIN','AGENTCALLBACKLOGIN') order by time_id desc limit 1;"; $stmtB = "SELECT agent,time_id,data1 FROM queue_log where agent='Agent/$VLA_user[$k]' and verb IN('AGENTLOGIN','AGENTCALLBACKLOGIN') and time_id > $check_time order by time_id desc limit 1;";
$rsltB=mysql_query($stmtB, $linkB); $rsltB=mysql_query($stmtB, $linkB);
if ($DB) {echo "<BR>$stmtB\n";} if ($DB) {echo "<BR>$stmtB\n";}
$qml_ct = mysql_num_rows($rsltB); $qml_ct = mysql_num_rows($rsltB);
+4 -2
View File
@@ -1,7 +1,7 @@
<?php <?php
# user_status.php # user_status.php
# #
# Copyright (C) 2010 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2 # Copyright (C) 2011 Matt Florell <vicidial@gmail.com> LICENSE: AGPLv2
# #
# CHANGES # CHANGES
# #
@@ -16,6 +16,7 @@
# 91212-0656 - Added more complete logging of Emergency Logout process # 91212-0656 - Added more complete logging of Emergency Logout process
# 100309-0544 - Added queuemetrics_loginout option # 100309-0544 - Added queuemetrics_loginout option
# 101108-0032 - Added ADDMEMBER queue_log code # 101108-0032 - Added ADDMEMBER queue_log code
# 110124-1134 - Small query fix for large queue_log tables
# #
header ("Content-type: text/html; charset=utf-8"); header ("Content-type: text/html; charset=utf-8");
@@ -66,6 +67,7 @@ $StarTtimE = date("U");
$TODAY = date("Y-m-d"); $TODAY = date("Y-m-d");
$NOW_TIME = date("Y-m-d H:i:s"); $NOW_TIME = date("Y-m-d H:i:s");
$ip = getenv("REMOTE_ADDR"); $ip = getenv("REMOTE_ADDR");
$check_time = ($StarTtimE - 86400);
if (!isset($begin_date)) {$begin_date = $TODAY;} if (!isset($begin_date)) {$begin_date = $TODAY;}
if (!isset($end_date)) {$end_date = $TODAY;} if (!isset($end_date)) {$end_date = $TODAY;}
@@ -371,7 +373,7 @@ if ($stage == "log_agent_out")
$agent_logged_in=''; $agent_logged_in='';
$time_logged_in='0'; $time_logged_in='0';
$stmtB = "SELECT agent,time_id,data1 FROM queue_log where agent='Agent/" . mysql_real_escape_string($user) . "' and verb IN('AGENTLOGIN','AGENTCALLBACKLOGIN') order by time_id desc limit 1;"; $stmtB = "SELECT agent,time_id,data1 FROM queue_log where agent='Agent/" . mysql_real_escape_string($user) . "' and verb IN('AGENTLOGIN','AGENTCALLBACKLOGIN') and time_id > $check_time order by time_id desc limit 1;";
$rsltB=mysql_query($stmtB, $linkB); $rsltB=mysql_query($stmtB, $linkB);
if ($DB) {echo "<BR>$stmtB\n";} if ($DB) {echo "<BR>$stmtB\n";}
$qml_ct = mysql_num_rows($rsltB); $qml_ct = mysql_num_rows($rsltB);