From 0bc59a7797d28d154fdf90c7bd0f54de787bc709 Mon Sep 17 00:00:00 2001 From: aydreeihn <adriane@enhancesoft.com> Date: Tue, 16 Oct 2018 12:21:21 -0500 Subject: [PATCH] Increase Batch Size/Cleanup Code --- include/class.report.php | 38 ++++++++++--------- include/class.thread.php | 30 +++++++++------ .../streams/core/26fd79dc-00c949a6.task.php | 9 +++-- 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/include/class.report.php b/include/class.report.php index c2aa391ef..dbff0ba38 100644 --- a/include/class.report.php +++ b/include/class.report.php @@ -78,30 +78,29 @@ class OverviewReport { function getPlotData() { list($start, $stop) = $this->getDateRange(); $states = array("created", "closed", "reopened", "assigned", "overdue", "transferred"); - $event_ids = array(); - foreach ($states as $state) { - $eid = Event::getIdByName($state); - $event_ids[] = $eid; - } + $event_ids = Event::getIds(); # Fetch all types of events over the timeframe - $res = db_query('SELECT DISTINCT(state) FROM '.THREAD_EVENT_TABLE + $res = db_query('SELECT DISTINCT(E.name) FROM '.THREAD_EVENT_TABLE + .' T JOIN '.EVENT_TABLE . ' E ON E.id = T.event_id' .' WHERE timestamp BETWEEN '.$start.' AND '.$stop - .' AND event_id IN ('.implode($event_ids).')' + .' AND T.event_id IN ('.implode(",",$event_ids).')' .' ORDER BY 1'); $events = array(); while ($row = db_fetch_row($res)) $events[] = $row[0]; # TODO: Handle user => db timezone offset # XXX: Implement annulled column from the %ticket_event table - $res = db_query('SELECT event_id, DATE_FORMAT(timestamp, \'%Y-%m-%d\'), ' + $res = db_query('SELECT H.name, DATE_FORMAT(timestamp, \'%Y-%m-%d\'), ' .'COUNT(DISTINCT T.id)' .' FROM '.THREAD_EVENT_TABLE. ' E ' + . ' LEFT JOIN '.EVENT_TABLE. ' H + ON (E.event_id = H.id)' .' JOIN '.THREAD_TABLE. ' T ON (T.id = E.thread_id AND T.object_type = "T") ' .' WHERE E.timestamp BETWEEN '.$start.' AND '.$stop .' AND NOT annulled' - .' AND E.event_id IN ('.implode($event_ids).')' + .' AND E.event_id IN ('.implode(",",$event_ids).')' .' GROUP BY E.event_id, DATE_FORMAT(E.timestamp, \'%Y-%m-%d\')' .' ORDER BY 2, 1'); # Initialize array of plot values @@ -145,6 +144,11 @@ class OverviewReport { function getTabularData($group='dept') { global $thisstaff; + $event_ids = Event::getIds(); + $event = function ($name) use ($event_ids) { + return $event_ids[$name]; + }; + list($start, $stop) = $this->getDateRange(); $times = ThreadEvent::objects() ->constrain(array( @@ -154,8 +158,8 @@ class OverviewReport { )) ->constrain(array( 'thread__events' => array( - 'thread__events__event_id' => Event::getIdByName('created'), - 'event_id' => Event::getIdByName('closed'), + 'thread__events__event_id' => $event('created'), + 'event_id' => $event('closed'), 'annulled' => 0, ), )) @@ -180,27 +184,27 @@ class OverviewReport { ->aggregate(array( 'Opened' => SqlAggregate::COUNT( SqlCase::N() - ->when(new Q(array('event_id' => Event::getIdByName('created'))), 1) + ->when(new Q(array('event_id' => $event('created'))), 1) ), 'Assigned' => SqlAggregate::COUNT( SqlCase::N() - ->when(new Q(array('event_id' => Event::getIdByName('assigned'))), 1) + ->when(new Q(array('event_id' => $event('assigned'))), 1) ), 'Overdue' => SqlAggregate::COUNT( SqlCase::N() - ->when(new Q(array('event_id' => Event::getIdByName('overdue'))), 1) + ->when(new Q(array('event_id' => $event('overdue'))), 1) ), 'Closed' => SqlAggregate::COUNT( SqlCase::N() - ->when(new Q(array('event_id' => Event::getIdByName('closed'))), 1) + ->when(new Q(array('event_id' => $event('closed'))), 1) ), 'Reopened' => SqlAggregate::COUNT( SqlCase::N() - ->when(new Q(array('event_id' => Event::getIdByName('reopened'))), 1) + ->when(new Q(array('event_id' => $event('reopened'))), 1) ), 'Deleted' => SqlAggregate::COUNT( SqlCase::N() - ->when(new Q(array('event_id' => Event::getIdByName('deleted'))), 1) + ->when(new Q(array('event_id' => $event('deleted'))), 1) ), )); diff --git a/include/class.thread.php b/include/class.thread.php index a2dbb5065..08f2bc68b 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -2075,27 +2075,33 @@ class Event extends VerySimpleModel { } function getNameById($id) { - $row = Event::objects() - ->filter(array('id'=>$id)) - ->values_flat('name') - ->first(); - - return $row ? $row[0] : 0; + return array_search($id, self::getIds()); } function getIdByName($name) { - $row = Event::objects() - ->filter(array('name'=>$name)) - ->values_flat('id') - ->first(); - - return $row ? $row[0] : 0; + $ids = self::getIds(); + return $ids[$name] ?: 0; } function getDescription() { return $this->description; } + static function getIds() { + static $ids; + + if (!isset($ids)) { + $ids = array(); + $events = static::objects()->values_flat('id', 'name'); + foreach ($events as $row) { + list($id, $name) = $row; + $ids[$name] = $id; + } + } + + return $ids; + } + static function create($vars=false, &$errors=array()) { $event = new static($vars); return $event; diff --git a/include/upgrader/streams/core/26fd79dc-00c949a6.task.php b/include/upgrader/streams/core/26fd79dc-00c949a6.task.php index e41b6c778..d3d6a2084 100644 --- a/include/upgrader/streams/core/26fd79dc-00c949a6.task.php +++ b/include/upgrader/streams/core/26fd79dc-00c949a6.task.php @@ -13,11 +13,11 @@ class EventEnumRemoval extends MigrationTask { $this->queue = $stuff['queue']; $this->skipList = $stuff['skipList']; while (!$this->isFinished()) - $this->do_batch(30, 500); + $this->do_batch(30, 5000); } function run($max_time) { - $this->do_batch($max_time * 0.9, 500); + $this->do_batch($max_time * 0.9, 5000); } function isFinished() { @@ -69,8 +69,9 @@ class EventEnumRemoval extends MigrationTask { // Force the log message to the database $ost->logDebug("Thread Event Migration", 'Found '.db_num_rows($res) .' events to migrate', true); - if(!db_num_rows($res)) - return 0; //Nothing else to do!! + + if(!db_num_rows($res)) + return 0; //Nothing else to do!! $this->queue = array(); while (list($id, $state, $eventId, $eventName)=db_fetch_row($res)) { -- GitLab