-
Type: Improvement
-
Status: Closed (View Workflow)
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: 2.5 Larks
-
Fix Version/s: 2.6 Larks
-
Labels:None
-
Sprint:2.5 Larks, 2.6 Larks
Right now when new topic is created, we have this code in controller:
public ModelAndView createTopic(@Valid @ModelAttribute TopicDto topicDto, BindingResult result, @RequestParam(BRANCH_ID) Long branchId) throws NotFoundException { Branch branch = branchService.get(branchId); if (result.hasErrors()) { return new ModelAndView(TOPIC_VIEW) .addObject(BRANCH_ID, branchId) .addObject(TOPIC_DTO, topicDto) .addObject(SUBMIT_URL, "/topics/new?branchId=" + branchId) .addObject(BREADCRUMB_LIST, breadcrumbBuilder.getForumBreadcrumb(branch)); } Topic topic = topicDto.getTopic(); topic.setBranch(branch); Topic createdTopic = topicModificationService.createTopic(topic, topicDto.getBodyText()); lastReadPostService.markTopicAsRead(createdTopic); return new ModelAndView(REDIRECT_URL + createdTopic.getId()); }
Which means that we create several transactions which is bad, there should be a single call to the service.
Additionally, in the service:
public Topic createTopic(Topic topicDto, String bodyText) throws NotFoundException { .... branch.addTopic(topic); branchDao.saveOrUpdate(branch); }
Which means that we load all topics within the branch in order to save a new topic. This should be changed so that Topic saves the relationship in Branch-Topic association (inverse=true is the keyword to google for).