Improved tag edit performance

Post history rewrite happens only when tag has really changed its name.
This commit is contained in:
Marcin Kurczewski 2014-10-15 20:03:32 +02:00
parent 34e220d465
commit 1b82504f08

View file

@ -128,6 +128,8 @@ class TagService
public function updateTag(Tag $tag, TagEditFormData $formData) public function updateTag(Tag $tag, TagEditFormData $formData)
{ {
$oldName = $tag->getName();
$transactionFunc = function() use ($tag, $formData) $transactionFunc = function() use ($tag, $formData)
{ {
$this->validator->validate($formData); $this->validator->validate($formData);
@ -138,17 +140,26 @@ class TagService
if ($formData->banned !== $tag->isBanned()) if ($formData->banned !== $tag->isBanned())
$tag->setBanned(boolval($formData->banned)); $tag->setBanned(boolval($formData->banned));
if ($formData->implications !== null)
$this->updateImplications($tag, $formData->implications);
if ($formData->suggestions !== null)
$this->updateSuggestions($tag, $formData->suggestions);
return $this->tagDao->save($tag); return $this->tagDao->save($tag);
}; };
$ret = $this->transactionManager->commit($transactionFunc); $ret = $this->transactionManager->commit($transactionFunc);
$transactionFunc = function() use ($tag) if ($oldName !== $tag->getName())
{ {
$posts = $this->postDao->findByTagName($tag->getName()); $transactionFunc = function() use ($tag)
foreach ($posts as $post) {
$this->historyService->saveSnapshot($this->historyService->getPostChangeSnapshot($post)); $posts = $this->postDao->findByTagName($tag->getName());
}; foreach ($posts as $post)
$this->transactionManager->commit($transactionFunc); $this->historyService->saveSnapshot($this->historyService->getPostChangeSnapshot($post));
};
$this->transactionManager->commit($transactionFunc);
}
$this->exportJson(); $this->exportJson();
return $ret; return $ret;