@@ -127,9 +127,9 @@ def _md5_on_record(self, img_file: ImageFile, imgid: int, orig_file_name: str):
127127 logger .exception (e )
128128 img_file .state = ImageFileStateEnum .ERROR .value
129129
130- def do_cleanup_dup_same_obj ( # TODO: Not working and not tested anyway
130+ def do_cleanup_dup_same_obj (
131131 self , current_user_id : UserIDT , prj_id : ProjectIDT , max_deletes : int
132- ) -> str :
132+ ) -> str : #
133133 """
134134 Simplest duplication pattern. Inside the same object there are several identical images.
135135 """
@@ -139,7 +139,7 @@ def do_cleanup_dup_same_obj( # TODO: Not working and not tested anyway
139139 orig_img = aliased (Image , name = "orig" )
140140 orig_file = aliased (ImageFile , name = "orig_file" )
141141 qry = self .session .query (
142- orig_img .file_name , orig_img .imgid , Image , ImageFile
142+ orig_img .orig_file_name , orig_img .imgid , Image , ImageFile
143143 ) # Select what to delete
144144 qry = (
145145 qry .join (ObjectHeader , ObjectHeader .objid == Image .objid )
@@ -166,13 +166,6 @@ def do_cleanup_dup_same_obj( # TODO: Not working and not tested anyway
166166 ImageFile .state == ImageFileStateEnum .OK .value ,
167167 ),
168168 )
169- qry = qry .join (
170- orig_file ,
171- and_ (
172- orig_file .path == orig_img .file_name ,
173- orig_file .state == ImageFileStateEnum .OK .value ,
174- ),
175- )
176169 # and the same value of course
177170 qry = qry .filter (
178171 and_ (
@@ -202,7 +195,10 @@ def do_cleanup_dup_same_obj( # TODO: Not working and not tested anyway
202195 continue
203196 # Even if MD5s match, be paranoid and compare files
204197 orig_path = self .vault .image_path (orig_file_name )
205- dup_path = self .vault .image_path (an_image .file_name )
198+ img_file_name = Image .img_from_id_and_orig (
199+ an_image .imgid , an_image .orig_file_name
200+ )
201+ dup_path = self .vault .image_path (img_file_name )
206202 assert orig_path != dup_path
207203 orig_exists = exists (orig_path )
208204 dup_exists = exists (dup_path )
@@ -232,7 +228,7 @@ def do_cleanup_dup_same_obj( # TODO: Not working and not tested anyway
232228 # Do the cleanup
233229 deleted_imgids .add (an_image .imgid )
234230 if dup_exists :
235- remover .add_files ([an_image . file_name ])
231+ remover .add_files ([img_file_name ])
236232 self .session .delete (an_image )
237233 self .session .delete (an_image_file )
238234 # Wait for the files handled
0 commit comments