Uploaded image for project: 'JCommune'
  1. JCommune
  2. JC-1571

Performance problems with new topic creation

VotersWatchers
    XMLWordPrintable

    Details

    • 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

      Description

      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).

        Attachments

          Structure

            Activity

              People

              • Assignee:
                ctapobep Stanislav Bashkyrtsev
                Reporter:
                ctapobep Stanislav Bashkyrtsev
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Structure Helper Panel