#153 Avoid redundant DB operations
Merged 3 years ago by lholecek. Opened 3 years ago by lholecek.
taskotron/ lholecek/resultsdb avoid-redundant-db-operations  into  develop

Avoid redundant DB operations
Lukas Holecek • 3 years ago  
@@ -325,7 +325,6 @@ 

      db.session.add(job)

      db.session.commit()

  

-     db.session.add(job)

      return jsonify(SERIALIZE(job)), 201

  

  
@@ -527,7 +526,6 @@ 

              # TODO: add configurable default "empty" URL

              testcase = Testcase(args['testcase_name'], "")

              db.session.add(testcase)

-             db.session.commit()

  

      outcome = args['outcome'].strip().upper()

      if outcome not in RESULT_OUTCOME:
@@ -566,8 +564,6 @@ 

      db.session.add(result)

      db.session.commit()

  

-     db.session.add(result)

- 

      if app.config['MESSAGE_BUS_PUBLISH']:

          plugin = load_messaging_plugin(

              name=app.config['MESSAGE_BUS_PLUGIN'],
@@ -652,7 +648,6 @@ 

          # return jsonify({"message": e.message}), 400

          return jsonify({"message": "Testcase with this name already exists"}), 400

  

-     db.session.add(testcase)

      return jsonify(SERIALIZE(testcase)), 201

  

  

@@ -314,7 +314,6 @@ 

      db.session.add(group)

      db.session.commit()

  

-     db.session.add(group)

      return jsonify(SERIALIZE(group)), 201

  

  
@@ -641,7 +640,6 @@ 

          testcase = Testcase(name=tc['name'])

      testcase.ref_url = tc.get('ref_url', testcase.ref_url)

      db.session.add(testcase)

-     db.session.commit()

  

      # args[groups] is a list of strings(uuid) or dicts(group object)

      #  when a group defined by the string is not found, new is created
@@ -663,7 +661,6 @@ 

              group.ref_url = grp.get('ref_url', group.ref_url)

  

              db.session.add(group)

-             db.session.commit()

              groups.append(group)

  

      result = Result(testcase, outcome, groups, args['ref_url'], args['note'])
@@ -698,7 +695,6 @@ 

      db.session.add(result)

      db.session.commit()

  

-     db.session.add(result)

      app.logger.debug("Created new result for testcase %s with outcome %s", testcase.name, outcome)

  

      if app.config['MESSAGE_BUS_PUBLISH']:
@@ -800,7 +796,6 @@ 

      db.session.add(testcase)

      db.session.commit()

  

-     db.session.add(testcase)

      return jsonify(SERIALIZE(testcase)), 201

  

  

no initial comment

I'm not sure what's the idea behind the duplicate db.session.add() calls.

rebased onto c0637ef

3 years ago

Pull-Request has been merged by lholecek

3 years ago