Faster preloading
This commit is contained in:
parent
e6b37afa8c
commit
3a2a686b6c
2 changed files with 2 additions and 4 deletions
|
@ -40,7 +40,7 @@ abstract class AbstractCrudModel implements IModel
|
||||||
$stmt = new SqlSelectStatement();
|
$stmt = new SqlSelectStatement();
|
||||||
$stmt->setColumn('*');
|
$stmt->setColumn('*');
|
||||||
$stmt->setTable(static::getTableName());
|
$stmt->setTable(static::getTableName());
|
||||||
$stmt->setCriterion(SqlInOperator::fromArray('id', SqlBinding::fromArray($ids)));
|
$stmt->setCriterion(SqlInOperator::fromArray('id', SqlBinding::fromArray(array_unique($ids))));
|
||||||
|
|
||||||
$rows = Database::fetchAll($stmt);
|
$rows = Database::fetchAll($stmt);
|
||||||
if ($rows)
|
if ($rows)
|
||||||
|
|
|
@ -187,7 +187,7 @@ class PostModel extends AbstractCrudModel
|
||||||
$postMap[$postId] = $post;
|
$postMap[$postId] = $post;
|
||||||
$tagsMap[$postId] = [];
|
$tagsMap[$postId] = [];
|
||||||
}
|
}
|
||||||
$postIds = array_keys($postMap);
|
$postIds = array_unique(array_keys($postMap));
|
||||||
|
|
||||||
$stmt = new SqlSelectStatement();
|
$stmt = new SqlSelectStatement();
|
||||||
$stmt->setTable('tag');
|
$stmt->setTable('tag');
|
||||||
|
@ -213,9 +213,7 @@ class PostModel extends AbstractCrudModel
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($tagsMap as $postId => $tags)
|
foreach ($tagsMap as $postId => $tags)
|
||||||
{
|
|
||||||
$postMap[$postId]->setCache('tags', $tags);
|
$postMap[$postId]->setCache('tags', $tags);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue