Skip to content

Commit

Permalink
Pre-reference check optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
ht2 committed Oct 7, 2016
1 parent f16bced commit 0ee2589
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions app/locker/repository/Statement/EloquentLinker.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ class EloquentLinker extends EloquentReader implements LinkerInterface {
public function updateReferences(array $statements, StoreOptions $opts) {
$this->voider = strpos(json_encode($statements), 'voided') !== false;
$this->downed = new Collection();
$this->to_update = array_map(function (\stdClass $statement) use ($opts) {
return $this->getModel($statement->id, $opts);
}, $statements);
$this->to_update = $this->getModels($statements, $opts);

while (count($this->to_update) > 0) {
$this->upLink($this->to_update[0], [], $opts);
Expand All @@ -44,6 +42,24 @@ protected function isReferencing(\stdClass $statement) {
);
}

/**
* Gets the statements as an array from the database.
* @param [\stdClass] $statements Statements
* @param StoreOptions $opts
* @return [Model]
*/
protected function getModels($statements, StoreOptions $opts) {
$statement_ids = array_map(function (\stdClass $statement) use ($opts) {
return $statement->id;
}, $statements);

$models = $this->where($opts)
->whereIn('statement.id', $statement_ids)
->get();

return $models->all();
}

/**
* Gets the statement as an associative array from the database.
* @param String $statement_id Statement's UUID.
Expand All @@ -54,7 +70,6 @@ protected function getModel($statement_id, StoreOptions $opts) {
$model = $this->where($opts)
->where('statement.id', $statement_id)
->first();

return $model;
}

Expand Down

0 comments on commit 0ee2589

Please sign in to comment.