Skip to content

Commit 4c9d811

Browse files
committed
Improve performance by only making 1 query
1 parent a0cac6e commit 4c9d811

File tree

1 file changed

+23
-14
lines changed
  • administrator/components/com_patchtester/PatchTester/Model

1 file changed

+23
-14
lines changed

administrator/components/com_patchtester/PatchTester/Model/PullsModel.php

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -328,23 +328,32 @@ public function requestFromGithub()
328328
// Dump the old data now
329329
$this->getDb()->truncateTable('#__patchtester_pulls');
330330

331-
foreach ($pulls as &$pull)
331+
// If there are no pulls to insert then bail
332+
if (empty($pulls))
333+
{
334+
return;
335+
}
336+
337+
$data = array();
338+
339+
foreach ($pulls as $pull)
332340
{
333341
// Build the data object to store in the database
334-
$data = new \stdClass;
335-
$data->pull_id = $pull->number;
336-
$data->title = $pull->title;
337-
$data->description = $pull->body;
338-
$data->pull_url = $pull->html_url;
342+
$pullData = array($pull->number, $pull->title, $pull->body, $pull->html_url);
343+
$data[] = implode($pullData, ',');
344+
}
339345

340-
try
341-
{
342-
$this->getDb()->insertObject('#__patchtester_pulls', $data, 'id');
343-
}
344-
catch (\RuntimeException $e)
345-
{
346-
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_ERROR_INSERT_DATABASE', $e->getMessage()));
347-
}
346+
$query = $this->getDb()->getQuery();
347+
$query->insert('#__patchtester_pulls')->columns('pull_id, title, description, pull_url')->values($data);
348+
$this->getDb()->setQuery($query);
349+
350+
try
351+
{
352+
$this->getDb()->execute();
353+
}
354+
catch (\RuntimeException $e)
355+
{
356+
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_ERROR_INSERT_DATABASE', $e->getMessage()));
348357
}
349358
}
350359
else

0 commit comments

Comments
 (0)