From 2bf8f08228f728ad9c5075a3047cb9213c5ec75e Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Thu, 22 Sep 2022 14:25:07 +1000 Subject: [PATCH] fix BUG-107: view / pagination gets out of whack --- BUGs | 3 +-- pa_job_manager.py | 32 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/BUGs b/BUGs index b99a0fc..e0ab6c7 100644 --- a/BUGs +++ b/BUGs @@ -1,7 +1,6 @@ -### Next: 107 +### Next: 108 BUG-100: I managed to get 2 photos matching mich in the NOT_WORKING photo (probably dif refimgs but same p.tag?) BUG-105: show unmatched needs to handle overrides (ignore face, etc.) BUG-106: cant add trudy /pat? as refimgs via FaceDBox - seems the cropped trudy face is not sufficient to find a face, how odd... (it came from a face bbox, BUT, I have grown the face seln by 10%?) -BUG-107: view / pagination gets out of whack - suss its paging in, then a new scan resets file/ordering (offset most likely?) diff --git a/pa_job_manager.py b/pa_job_manager.py index c12ff73..d00c804 100644 --- a/pa_job_manager.py +++ b/pa_job_manager.py @@ -982,9 +982,9 @@ def DisconnectSingleNoMatchOverride( job, o ): session.add( DisconnectedNoMatchOverride( face=f.face, type_id=o.type_id ) ) # now deal with 'renaming' the metadata on FS - p=f'{SettingsMPath()}/no_match_overrides/' - fname=f'{p}{o.face_id}_{ot.name}' - new_fname=f'{p}0_{ot.name}_{uuid.uuid4()}' + mpath=f'{SettingsMPath()}/no_match_overrides/' + fname=f'{mpath}{o.face_id}_{ot.name}' + new_fname=f'{mpath}0_{ot.name}_{uuid.uuid4()}' try: if os.path.exists( fname ): os.replace( fname, new_fname ) @@ -1581,6 +1581,18 @@ def find_last_successful_ai_scan(job): return j.last_update.timestamp() return 0 +#################################################################################################################################### +# when an import job actually finds new files, then the pa_user_state caches will become invalid (offsets are now wrong) +#################################################################################################################################### +def DeleteOldPA_UserState(job): +# clear them out for now - this is 'dumb', just delete ALL. Eventually, can do this based on just the path &/or whether the last_used is +# newer than this delete moment (only would be a race condition between an import changing things and someone simultaneously viewing) +# path=[jex.value for jex in job.extra if jex.name == "path"][0] + session.query(PA_UserState).delete() + return + + + #################################################################################################################################### # JobImportDir(): job that scan import dir and processes entries in there - key function that uses os.walk() to traverse the # file system and calls AddFile()/AddDir() as necessary @@ -1689,6 +1701,8 @@ def JobImportDir(job): if found_new_files: job.extra.append( JobExtra( name="new_files", value=found_new_files ) ) session.add(job) + # this will invalidate pa_user_state for this path's contents (offsets are now wrong), clear them out + DeleteOldPA_UserState(job) rm_cnt=HandleAnyFSDeletions(job) @@ -2206,8 +2220,8 @@ def ReloadMetadata(job): AddLogForJob(job, f"INFO: Loading/Retrieving any Metatdata...") # no path, then no metadata (probably first ever run) - p = SettingsMPath() - if not p: + mpath = SettingsMPath() + if not mpath: FinishJob( job, "No metadata path - skipping" ) return False @@ -2215,7 +2229,7 @@ def ReloadMetadata(job): CopyOverrides() # process Metadata on FS for no_match_overrides (disco ones, will have 0 as face_id) - fnames = glob.glob( f'{p}/no_match_overrides/*' ) + fnames = glob.glob( f'{mpath}/no_match_overrides/*' ) for fname in fnames: # type derived from fname (e.g. 0_Too Young_uuid*, 1_Too Young, 2_Ingore Face, etc.) match=re.search( '(\d+)_([^_\.]+)', fname ) @@ -2234,12 +2248,12 @@ def ReloadMetadata(job): session.add( DisconnectedNoMatchOverride( face=face_data, type_id=otype.id ) ) if face_id: try: - os.replace( fname, f'{p}no_match_overrides/0_{otype.name}_{uuid.uuid4()}' ) + os.replace( fname, f'{mpath}no_match_overrides/0_{otype.name}_{uuid.uuid4()}' ) except Exception as ex: print( f"ERROR: renaming no-match metadata on filesystem failed: {ex}" ) # process Metadata on FS for force_match_overrides (disco ones, will have 0 as face_id) - fnames = glob.glob( f'{p}force_match_overrides/*' ) + fnames = glob.glob( f'{mpath}force_match_overrides/*' ) for fname in fnames: # person derived from fname (e.g. 0_ddp_uuid*, 1_ddp, 2_mich, etc.) match=re.search( '(\d+)_([^_]+)', fname ) @@ -2262,7 +2276,7 @@ def ReloadMetadata(job): # if face>0, then we need to move the FS copy to a disco if face_id: try: - os.replace( fname, f'{p}force_match_overrides/0_{p.tag}_{uuid.uuid4()}' ) + os.replace( fname, f'{mpath}force_match_overrides/0_{p.tag}_{uuid.uuid4()}' ) except Exception as ex: print( f"ERROR: renaming force-match metadata on filesystem failed: {ex}" )