Faster preloading

This commit is contained in:
Marcin Kurczewski 2014-02-24 14:42:25 +01:00
parent e6b37afa8c
commit 3a2a686b6c
2 changed files with 2 additions and 4 deletions

View file

@ -40,7 +40,7 @@ abstract class AbstractCrudModel implements IModel
$stmt = new SqlSelectStatement();
$stmt->setColumn('*');
$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);
if ($rows)

View file

@ -187,7 +187,7 @@ class PostModel extends AbstractCrudModel
$postMap[$postId] = $post;
$tagsMap[$postId] = [];
}
$postIds = array_keys($postMap);
$postIds = array_unique(array_keys($postMap));
$stmt = new SqlSelectStatement();
$stmt->setTable('tag');
@ -213,10 +213,8 @@ class PostModel extends AbstractCrudModel
}
foreach ($tagsMap as $postId => $tags)
{
$postMap[$postId]->setCache('tags', $tags);
}
}