Page 1 of 1

why are closer logs updated this way?

PostPosted: Mon Aug 26, 2013 8:48 pm
by bobbymc
how come in many areas we search from 4 hours ago or 1 hour ago? why not jsut order by call_date desc?

this is from the svn trunk but also all other versions:

Code: Select all
                $four_hours_ago = date("Y-m-d H:i:s", mktime(date("H")-4,date("i"),date("s"),date("m"),date("d"),date("Y")));

                if ($VLA_inOUT == 'INBOUND')
                        {
                        $vcl_statusSQL='';
                        if ($VDstatus == 'INCALL') {$vcl_statusSQL = ",status='$status_dispo'";}
                        $stmt = "UPDATE vicidial_closer_log set end_epoch='$StarTtime', length_in_sec='$length_in_sec' $vcl_statusSQL where lead_id='$lead_id' and user='$user' and call_date > \"$four_hours_ago\" order by call_date desc limit 1;";
                        if ($DB) {echo "$stmt\n";}
                        $rslt=mysql_query($stmt, $link);
                        if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00062',$user,$server_ip,$session_name,$one_mysql_log);}
                        $affected_rows = mysql_affected_rows($link);
                        if ($affected_rows > 0)
                                {
                                echo "$uniqueid\n$channel\n";

                        #       $fp = fopen ("./vicidial_debug.txt", "a");
                        #       fwrite ($fp, "$NOW_TIME|INBND_LOG_4|$VDstatus|$uniqueid|$lead_id|$user|$inOUT|$length_in_sec|$VDterm_reason|$VDvicidial_id|$start_epoch|$stmt|\n");
                        #       fclose($fp);
                                }
                        else
                                {
                                $fp = fopen ("./vicidial_debug.txt", "a");
                                fwrite ($fp, "$NOW_TIME|INBND_LOG_2|$uniqueid|$lead_id|$user|$inOUT|$length_in_sec|$VDterm_reason|$VDvicidial_id|$start_epoch|\n");
                                fclose($fp);
                                }
                        }

Re: why are closer logs updated this way?

PostPosted: Tue Aug 27, 2013 5:41 am
by mflorell
Because we had instances where something went wrong and a call from several days ago being updated. This prevents that from happening, and it shouldn't have much of an effect on the time it takes to run the query.

Re: why are closer logs updated this way?

PostPosted: Wed Aug 28, 2013 2:22 am
by bobbymc
but at this point would there already be a new record existing since you order by call_date desc limit 1? this would already give you the latest log that was generated when the call came in or was placed? why the need to also check the time?

Re: why are closer logs updated this way?

PostPosted: Thu Nov 13, 2014 7:26 pm
by bobbymc
ummmmm.. this is client code....

Re: why are closer logs updated this way?

PostPosted: Fri Nov 14, 2014 3:00 am
by DomeDan
bobbymc: that post from angel1092 is a copy of an other post on an other thread, its because its a bot that want to write spam, they know they have to wait a few days and do a normal post first etc.

and matt told you the reason, even though it should work with "order by call_date desc limit 1" and we dont know any reason why it shouldnt work, there has been instances where a query updates the wrong record.
the 4-hour part is just a extra safety to prevent that bug from appearing,
even tough the bug might not happen to you ever, the extra statement in the query does not slow down the query so its better to leave it there to prevent that rare bug

Re: why are closer logs updated this way?

PostPosted: Wed Nov 19, 2014 8:30 am
by bobbymc
Thank you for the explanation