We'd love to hear from you! Provide  feedback  to earn a badge today. Take our quick survey
You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

Commit at an interval of records processed such as every 100 or 1000 records

Accepted answer
11
Views
2
Comments
edited Aug 19, 2018 11:15AM in Customer Portal 2 comments

Content

Hi,

I have a loop that goes through *all* our incidents, some 250k. Code is below for what happens.

I raised a SR saying it wasn't performing as expecting as an arbitrary number were getting saved. They suggested "committing at an interval of records processed such as every 100 or 1000 records"

My question would be how I'd go about it? In fact, how would I optimise the code below? I was thinking of rather than deleting, I could update the record...

Code Snippet

             require_once(get_cfg_var('doc_root')."/ConnectPHP/Connect_init.php");
use RightNow\Connect\v1_3 as RNCPHP;
initConnectAPI();

		for ($x = 0; $x <= 50; $x++) {
			$query_string = "SELECT Misc.incident_stats FROM Misc.incident_stats LIMIT 10000";
			$destroy = RNCPHP\ROQL::queryObject($query_string)-> next();
			while($destroyEverything = $destroy->next()){
				$destroyEverything->destroy();
				RNCPHP\ConnectAPI::commit();
			}
		}	
		
		$a = Array();
		for ($x = 0; $x <= 500000; $x += 10000) {
			$r = RNCPHP\ROQL::query("SELECT ID FROM Incident WHERE Incident.Interface.ID=1 LIMIT ".$x.",10000" )->next();
			while($i = $r->next()) {
				$a[]=$i["ID"];
			}
		}
		
		$inc = new RNCPHP\Misc\incident_stats();
		$inc->i_id = 1;
		$inc->open = count($a);
		$inc->StatusType = count($a);
		$inc->Queue = count($a);
		$inc->Status = count($a);
		$inc->save(RNCPHP\RNObject::SuppressAll);
		RNCPHP\ConnectAPI::commit();
		
		foreach ($a as $v) {
			$filter= new RNCPHP\AnalyticsReportSearchFilter;
			$filter->Name = 'i_id';
			$filter->Values = array( $v );
			$filters = new RNCPHP\AnalyticsReportSearchFilterArray;
			$filters[] = $filter;
			$ar= RNCPHP\AnalyticsReport::fetch(101471);
			$arr= $ar->run( 0, $filters,10 );
			$nrows= $arr->count();
			if ( $nrows)

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!