Skip to content

Commit 3d1de7b

Browse files
committed
optimize validate_all_crawls_successful()
1 parent b172d80 commit 3d1de7b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

backend/btrixcloud/basecrawls.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
UpdatedResponse,
4545
DeletedResponseQuota,
4646
CrawlSearchValuesResponse,
47-
FAILED_STATES,
4847
)
4948
from .pagination import paginated_format, DEFAULT_PAGE_SIZE
5049
from .utils import dt_now, get_origin, date_to_str
@@ -617,11 +616,18 @@ async def bulk_presigned_files(
617616
async def validate_all_crawls_successful(
618617
self, crawl_ids: List[str], org: Organization
619618
):
620-
"""Validate that crawls in list exist and did not fail or else raise exception"""
621-
for crawl_id in crawl_ids:
622-
crawl = await self.get_base_crawl(crawl_id, org)
623-
if crawl.state in FAILED_STATES:
624-
raise HTTPException(status_code=400, detail="invalid_failed_crawl")
619+
"""Validate that crawls in list exist and have a succesful state, or throw"""
620+
count = self.crawls.count_documents(
621+
{
622+
"_id": {"$in": crawl_ids},
623+
"oid": org.id,
624+
"state": {"$in": SUCCESSFUL_STATES},
625+
}
626+
)
627+
if count != len(crawl_ids):
628+
raise HTTPException(
629+
status_code=400, detail="invalid_failed_or_unfinished_crawl"
630+
)
625631

626632
async def add_to_collection(
627633
self, crawl_ids: List[str], collection_id: UUID, org: Organization

0 commit comments

Comments
 (0)