From fa2b47558b6a87f85fe5558ca6ca51a59d14c45f Mon Sep 17 00:00:00 2001 From: mattf Date: Mon, 24 Jan 2011 16:47:05 +0000 Subject: [PATCH] Small query fix for systems with large queue_log table git-svn-id: svn://192.168.202.10@1594 3d104415-ff17-0410-8863-d5cf3c621b8a --- agc_2-X/trunk/agi/agi-AGENT_route.agi | 2 +- agc_2-X/trunk/bin/AST_VDauto_dial.pl | 4 +++- agc_2-X/trunk/bin/AST_VDremote_agents.pl | 4 +++- agc_2-X/trunk/bin/AST_cleanup_agent_log.pl | 7 ++++--- agc_2-X/trunk/www/agc/vdc_db_query.php | 8 +++++--- agc_2-X/trunk/www/vicidial/admin.php | 8 +++++--- agc_2-X/trunk/www/vicidial/user_status.php | 6 ++++-- 7 files changed, 25 insertions(+), 14 deletions(-) diff --git a/agc_2-X/trunk/agi/agi-AGENT_route.agi b/agc_2-X/trunk/agi/agi-AGENT_route.agi index e9d3a4d1..a8336ee9 100644 --- a/agc_2-X/trunk/agi/agi-AGENT_route.agi +++ b/agc_2-X/trunk/agi/agi-AGENT_route.agi @@ -17,7 +17,7 @@ # ; 7. audio filename for invalid user id re-enter prompt, agent not available # ; 8. number of retry attempts to enter a valid user ID # ; 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 # ; 10. audio filename before sending call to no-agent route # ; 11. audio filename before sending call to no-agent route if agent active but diff --git a/agc_2-X/trunk/bin/AST_VDauto_dial.pl b/agc_2-X/trunk/bin/AST_VDauto_dial.pl index c5861b67..2a116abe 100644 --- a/agc_2-X/trunk/bin/AST_VDauto_dial.pl +++ b/agc_2-X/trunk/bin/AST_VDauto_dial.pl @@ -95,6 +95,7 @@ # 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 # 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; 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->execute or die "executing: $stmtA ", $dbhB->errstr; $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_STD = $SERVER_GMT; if ($isdst) {$LOCAL_GMT_OFF++;} + $check_time = ($secX - 86400); $GMT_now = ($secX - ($LOCAL_GMT_OFF * 3600)); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($GMT_now); diff --git a/agc_2-X/trunk/bin/AST_VDremote_agents.pl b/agc_2-X/trunk/bin/AST_VDremote_agents.pl index 723a10c6..278be224 100644 --- a/agc_2-X/trunk/bin/AST_VDremote_agents.pl +++ b/agc_2-X/trunk/bin/AST_VDremote_agents.pl @@ -37,6 +37,7 @@ # 100622-0917 - Added start_call_url function for remote agents, this launches a separate child script # 101108-0032 - Added ADDMEMBER queue_log code # 110103-1230 - Added queuemetrics_loginout NONE option +# 110124-1134 - Small query fix for large queue_log tables # ### 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';"; $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->execute or die "executing: $stmtB ", $dbhB->errstr; $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_STD = $SERVER_GMT; if ($isdst) {$LOCAL_GMT_OFF++;} + $check_time = ($secX - 86400); $GMT_now = ($secX - ($LOCAL_GMT_OFF * 3600)); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($GMT_now); diff --git a/agc_2-X/trunk/bin/AST_cleanup_agent_log.pl b/agc_2-X/trunk/bin/AST_cleanup_agent_log.pl index b3ae85a2..981fd382 100644 --- a/agc_2-X/trunk/bin/AST_cleanup_agent_log.pl +++ b/agc_2-X/trunk/bin/AST_cleanup_agent_log.pl @@ -10,7 +10,7 @@ # # This program only needs to be run by one server # -# Copyright (C) 2010 Matt Florell LICENSE: AGPLv2 +# Copyright (C) 2011 Matt Florell LICENSE: AGPLv2 # # CHANGES # 60711-0945 - Changed to DBI by Marin Blu @@ -27,6 +27,7 @@ # 100309-0555 - Added queuemetrics_loginout option # 100327-0926 - Added validation of four agent "sec" fields # 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 @@ -1561,7 +1562,7 @@ if ($enable_queuemetrics_logging > 0) ####################################################################### ##### 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->execute or die "executing: $stmtB ", $dbhB->errstr; $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 - $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->execute or die "executing: $stmtB ", $dbhB->errstr; $XN_records=$sthB->rows; diff --git a/agc_2-X/trunk/www/agc/vdc_db_query.php b/agc_2-X/trunk/www/agc/vdc_db_query.php index 7febd1f1..1875586e 100644 --- a/agc_2-X/trunk/www/agc/vdc_db_query.php +++ b/agc_2-X/trunk/www/agc/vdc_db_query.php @@ -266,10 +266,11 @@ # 101128-0108 - Added list override for webforms # 101208-0414 - Fixed Call Log dial bug (issue 393) # 110103-1343 - Added queuemetrics_loginout NONE option +# 110124-1134 - Small query fix for large queue_log tables # -$version = '2.4-172'; -$build = '110103-1343'; +$version = '2.4-173'; +$build = '110124-1134'; $mel=1; # Mysql Error Log enabled = 1 $mysql_log_count=365; $one_mysql_log=0; @@ -476,6 +477,7 @@ $MT[0]=''; $agents='@agents'; $US='_'; while (strlen($CIDdate) > 9) {$CIDdate = substr("$CIDdate", 1);} +$check_time = ($StarTtime - 86400); ##### Hangup Cause Dictionary ##### $hangup_cause_dictionary = array( @@ -5401,7 +5403,7 @@ if ($ACTION == 'userLOGout') # $affected_rows = mysql_affected_rows($linkB); $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); 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";} diff --git a/agc_2-X/trunk/www/vicidial/admin.php b/agc_2-X/trunk/www/vicidial/admin.php index fe5ffa58..5d9948c5 100644 --- a/agc_2-X/trunk/www/vicidial/admin.php +++ b/agc_2-X/trunk/www/vicidial/admin.php @@ -2631,12 +2631,13 @@ else # 101227-1320 - Added dialplan off toggle options # 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 +# 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 -$admin_version = '2.4-296'; -$build = '110111-1305'; +$admin_version = '2.4-297'; +$build = '110124-1134'; $STARTtime = date("U"); $SQLdate = date("Y-m-d H:i:s"); @@ -2647,6 +2648,7 @@ $active_lists=0; $inactive_lists=0; $modify_refresh_set=0; $modify_footer_refresh=0; +$check_time = ($STARTtime - 86400); $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); @@ -16549,7 +16551,7 @@ if ($ADD==62) $agent_logged_in=''; $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); if ($DB) {echo "
$stmtB\n";} $qml_ct = mysql_num_rows($rsltB); diff --git a/agc_2-X/trunk/www/vicidial/user_status.php b/agc_2-X/trunk/www/vicidial/user_status.php index 63b25906..98b476a5 100644 --- a/agc_2-X/trunk/www/vicidial/user_status.php +++ b/agc_2-X/trunk/www/vicidial/user_status.php @@ -1,7 +1,7 @@ LICENSE: AGPLv2 +# Copyright (C) 2011 Matt Florell LICENSE: AGPLv2 # # CHANGES # @@ -16,6 +16,7 @@ # 91212-0656 - Added more complete logging of Emergency Logout process # 100309-0544 - Added queuemetrics_loginout option # 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"); @@ -66,6 +67,7 @@ $StarTtimE = date("U"); $TODAY = date("Y-m-d"); $NOW_TIME = date("Y-m-d H:i:s"); $ip = getenv("REMOTE_ADDR"); +$check_time = ($StarTtimE - 86400); if (!isset($begin_date)) {$begin_date = $TODAY;} if (!isset($end_date)) {$end_date = $TODAY;} @@ -371,7 +373,7 @@ if ($stage == "log_agent_out") $agent_logged_in=''; $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); if ($DB) {echo "
$stmtB\n";} $qml_ct = mysql_num_rows($rsltB);