removing extra session.commits, and optimsing run_ai_on - dont reprocess faces if no new refimgs since last scan -- so we had set last_ai_scan on FILE as well

This commit is contained in:
2021-09-16 19:25:23 +10:00
parent e536b9217f
commit 4d0addb87b

View File

@@ -19,7 +19,7 @@ DEBUG=1
### SQLALCHEMY IMPORTS ###
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, Sequence, Float, ForeignKey, DateTime, LargeBinary, Boolean
from sqlalchemy import Column, Integer, String, Sequence, Float, ForeignKey, DateTime, LargeBinary, Boolean, func
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine
@@ -193,6 +193,7 @@ class File(Base):
day = Column(Integer)
woy = Column(Integer)
last_hash_date = Column(Float)
last_ai_scan = Column(Float)
faces = Column( LargeBinary )
faces_created_on = Column(Float)
@@ -754,7 +755,6 @@ def JobForceScan(job):
ProcessStorageDirs(job)
FinishJob(job, "Completed (forced remove and recreation of all file data)")
MessageToFE( job.id, "success", "Completed (forced remove and recreation of all file data)" )
session.commit()
return
##############################################################################
@@ -1674,7 +1674,6 @@ def MatchRefimgToFace( refimg_id, face_id, face_dist ):
session.query(FaceRefimgLink).filter(FaceRefimgLink.face_id==face_id).delete()
rfl = FaceRefimgLink( refimg_id = refimg_id, face_id = face_id, face_distance=face_dist )
session.add(rfl)
session.commit()
return
####################################################################################################################################
@@ -1764,11 +1763,18 @@ def ScanFileForPerson( job, e, force=False ):
for locn, face in zip( face_locations, unknown_encodings ):
AddFaceToFile( locn, face, e.id, model.id )
file_h.faces_created_on = time.time()
session.commit()
faces = session.query(Face).join(FaceFileLink).filter(FaceFileLink.file_eid==e.id).all()
# if there are no faces for this file, then dont go any futher
if not faces:
file_h.last_ai_scan = time.time()
return
ri_newest = session.query(func.max(Refimg.created_on)).first()[0]
# ri_newest has to exist, no ris and we dont process files but, if we have never scanned before, then last_ai_scan will be None
# if last_ai_scan is newer than the most recent refimg created, no need to look again, we have checked those refimgs in the last scan, just skip this file
if file_h.last_ai_scan and file_h.last_ai_scan > ri_newest:
return
dist={}
@@ -1784,6 +1790,7 @@ def ScanFileForPerson( job, e, force=False ):
# record matches in DB...
ProcessFaceMatches( job, dist, threshold, e, name )
file_h.last_ai_scan = time.time()
return