From 1b82504f08b7905134fc5d319a43be0853ebbc3a Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 15 Oct 2014 20:03:32 +0200 Subject: [PATCH] Improved tag edit performance Post history rewrite happens only when tag has really changed its name. --- src/Services/TagService.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Services/TagService.php b/src/Services/TagService.php index f673475f..1f4e046b 100644 --- a/src/Services/TagService.php +++ b/src/Services/TagService.php @@ -128,6 +128,8 @@ class TagService public function updateTag(Tag $tag, TagEditFormData $formData) { + $oldName = $tag->getName(); + $transactionFunc = function() use ($tag, $formData) { $this->validator->validate($formData); @@ -138,17 +140,26 @@ class TagService if ($formData->banned !== $tag->isBanned()) $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); }; $ret = $this->transactionManager->commit($transactionFunc); - $transactionFunc = function() use ($tag) + if ($oldName !== $tag->getName()) { - $posts = $this->postDao->findByTagName($tag->getName()); - foreach ($posts as $post) - $this->historyService->saveSnapshot($this->historyService->getPostChangeSnapshot($post)); - }; - $this->transactionManager->commit($transactionFunc); + $transactionFunc = function() use ($tag) + { + $posts = $this->postDao->findByTagName($tag->getName()); + foreach ($posts as $post) + $this->historyService->saveSnapshot($this->historyService->getPostChangeSnapshot($post)); + }; + $this->transactionManager->commit($transactionFunc); + } $this->exportJson(); return $ret;