@@ -149,7 +149,7 @@ async def add_collection(self, org: Organization, coll_in: CollIn):
149149
150150 slug = coll_in .slug or slug_from_name (coll_in .name )
151151
152- dedupeIndex = DedupeIndexStats () if coll_in .hasDedupeIndex else None
152+ indexStats = DedupeIndexStats () if coll_in .hasDedupeIndex else None
153153
154154 coll = Collection (
155155 id = coll_id ,
@@ -163,14 +163,11 @@ async def add_collection(self, org: Organization, coll_in: CollIn):
163163 access = coll_in .access ,
164164 defaultThumbnailName = coll_in .defaultThumbnailName ,
165165 allowPublicDownload = coll_in .allowPublicDownload ,
166- dedupeIndex = dedupeIndex ,
166+ indexStats = indexStats ,
167167 )
168168 try :
169169 await self .collections .insert_one (coll .to_dict ())
170170 await self .clear_org_previous_slugs_matching_slug (slug , org )
171- # create collection index
172- # if coll.dedupeIndex:
173- # await self.crawl_manager.create_coll_index(coll)
174171
175172 if crawl_ids :
176173 await self .crawl_ops .add_to_collection (crawl_ids , coll_id , org )
@@ -214,11 +211,11 @@ async def update_collection(
214211
215212 query ["modified" ] = dt_now ()
216213
217- if update .hasDedupeIndex and not coll .dedupeIndex :
218- query ["dedupeIndex " ] = DedupeIndexStats ().dict ()
214+ if update .hasDedupeIndex is True and not coll .indexStats :
215+ query ["indexStats " ] = DedupeIndexStats ().dict ()
219216 await self .update_coll_index (coll , org .id )
220217
221- elif not update .hasDedupeIndex and coll .dedupeIndex :
218+ elif update .hasDedupeIndex is False and coll .indexStats :
222219 await self .delete_coll_index (coll , org )
223220
224221 db_update = {"$set" : query }
@@ -541,7 +538,7 @@ async def list_collections(
541538 match_query ["name" ] = {"$regex" : regex_pattern , "$options" : "i" }
542539
543540 if has_dedupe_index is not None :
544- match_query ["dedupeIndex " ] = {"$ne" if has_dedupe_index else "$eq" : None }
541+ match_query ["indexStats " ] = {"$ne" if has_dedupe_index else "$eq" : None }
545542
546543 if public_colls_out :
547544 match_query ["access" ] = CollAccessType .PUBLIC
@@ -688,6 +685,11 @@ async def get_collection_crawl_ids(
688685
689686 async def update_coll_index (self , coll : Collection , oid : UUID , is_purge = False ):
690687 """create index import job"""
688+
689+ # don't update if no crawls if not purging removed crawls
690+ if not is_purge and not coll .crawlCount :
691+ return
692+
691693 crawler_image = self .crawl_ops .crawl_configs .get_channel_crawler_image (
692694 self .dedupe_importer_channel
693695 )
@@ -710,7 +712,7 @@ async def delete_coll_index(self, coll: Collection, org: Organization):
710712 """delete coll dedupe index, if possible"""
711713
712714 # if index is not idle, can't delete it yet
713- if coll .dedupeIndex and coll .indexState != "idle" :
715+ if coll .indexStats and coll .indexState != "idle" :
714716 raise HTTPException (status_code = 400 , detail = "dedupe_index_is_in_use" )
715717
716718 if coll .indexFile :
@@ -768,7 +770,7 @@ async def update_dedupe_index_stats(
768770 """update dedupe index stats for specified collection"""
769771 self .collections .find_one_and_update (
770772 {"_id" : coll_id },
771- {"$set" : {"dedupeIndex " : stats .dict () if stats else None }},
773+ {"$set" : {"indexStats " : stats .dict () if stats else None }},
772774 )
773775
774776 async def update_dedupe_index_info (
@@ -785,7 +787,7 @@ async def update_dedupe_index_info(
785787 query ["indexFile" ] = index_file .model_dump ()
786788
787789 res = self .collections .find_one_and_update (
788- {"_id" : coll_id , "dedupeIndex " : {"$ne" : None }},
790+ {"_id" : coll_id , "indexStats " : {"$ne" : None }},
789791 {"$set" : query },
790792 )
791793 return res is not None
@@ -883,7 +885,7 @@ async def update_collection_dates(
883885 latest_ts = None
884886
885887 # update_index is set, update dedupe index if it exists
886- if update_index and coll .dedupeIndex :
888+ if update_index and coll .indexStats :
887889 await self .update_coll_index (coll , oid )
888890
889891 match_query = {
@@ -952,7 +954,7 @@ async def add_successful_crawl_to_collections(
952954 async def purge_dedupe_index (self , coll_id : UUID , org : Organization ):
953955 """purge dedupe index on collection, raise exception if no index or not ready"""
954956 coll = await self .get_collection (coll_id , org .id )
955- if not coll .dedupeIndex :
957+ if not coll .indexStats :
956958 raise HTTPException (status_code = 400 , detail = "no_dedupe_index_on_collection" )
957959
958960 if coll .indexState not in ("ready" , "idle" ):
0 commit comments