Skip to content

Commit

Permalink
use bulk insert for unopened report table
Browse files Browse the repository at this point in the history
fix null request id in dev v2
  • Loading branch information
nkan-aot2 authored Feb 28, 2024
1 parent 4ee15d8 commit 44e74b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 4 additions & 3 deletions request-management-api/request_api/models/UnopenedReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class UnopenedReport(db.Model):
potentialmatches = db.Column(JSON, unique=False, nullable=False)

@classmethod
def insert(cls, row):
db.session.add(row)
def bulkinsert(cls, rows):
for row in rows:
db.session.add(row)
db.session.commit()
return DefaultMethodResult(True,'Report Row added',row.rawrequestid)
return DefaultMethodResult(True,'Report Rows added',map(lambda row: row.rawrequestid, rows))
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ async def generateunopenedreport(self):
enddate = date.today() - timedelta(days=int(self.waitdays))
requests = FOIRawRequest.getunopenedunactionedrequests(str(startdate), str(enddate))
alerts = []
alertdbrows = []
for request in requests:
potentialmatches = FOIRawRequest.getpotentialactionedmatches(request)
if len(potentialmatches) == 0:
alert = UnopenedReport()
alert.rawrequestid = request['requestid']
alert.date = date.today()
alert.rank = 1
UnopenedReport.insert(alert)
alertdbrows.append(alert)
alerts.append({"request": request, "rank": 1})
else:
highscore = 0
Expand All @@ -52,8 +53,9 @@ async def generateunopenedreport(self):
"requestid": m["requestrawdata"]['axisRequestId'],
"similarity": round(m['score'], 2)
} for m in potentialmatches]}
UnopenedReport.insert(alert)
alerts.append({"request": request, "rank": 2, "potentialmatches": alert.potentialmatches})
alertdbrows.append(alert)
alerts.append({"request": request, "rank": 2, "potentialmatches": alert.potentialmatches})
UnopenedReport.bulkinsert(alertdbrows)
alerts.sort(key=lambda a : a.get('potentialmatches', {'highscore': -1})['highscore'])
senderservice().send(
subject="Intake Unopened Request Report: " + str(date.today()),
Expand Down Expand Up @@ -141,7 +143,7 @@ def generateemailhtml(self, alerts):
<td>
'''
for m in alert['potentialmatches']['matches']:
emailhtml += (m.get('requestid', '') + " - similarity: " + str(m['similarity']*100) + "%<br>")
emailhtml += ((m['requestid'] or '') + " - similarity: " + str(m['similarity']*100) + "%<br>")
emailhtml = emailhtml[:-4]
emailhtml += '''</td>
<td>''' + alert['request']['requestrawdata']['descriptionTimeframe']['description'][0:99] + '''...</td>
Expand Down

0 comments on commit 44e74b0

Please sign in to comment.