|
20 | 20 |
|
21 | 21 | from fastapi import APIRouter, Depends, Request, HTTPException, Query |
22 | 22 | from starlette.requests import Headers |
23 | | -from pymongo import ReturnDocument |
| 23 | +import pymongo |
24 | 24 | import aiohttp |
25 | 25 |
|
26 | 26 | from .pagination import DEFAULT_PAGE_SIZE, paginated_format |
|
48 | 48 | ListFilterType, |
49 | 49 | ProfileSearchValuesResponse, |
50 | 50 | ) |
51 | | -from .utils import dt_now, str_to_date |
| 51 | +from .utils import dt_now, str_to_date, case_insensitive_collation |
52 | 52 |
|
53 | 53 | if TYPE_CHECKING: |
54 | 54 | from .orgs import OrgOps |
@@ -106,6 +106,26 @@ def set_crawlconfigs(self, crawlconfigs): |
106 | 106 | """set crawlconfigs ops""" |
107 | 107 | self.crawlconfigs = crawlconfigs |
108 | 108 |
|
| 109 | + async def init_index(self): |
| 110 | + """init lookup index""" |
| 111 | + await self.profiles.create_index( |
| 112 | + [("oid", pymongo.ASCENDING), ("name", pymongo.ASCENDING)], |
| 113 | + collation=case_insensitive_collation, |
| 114 | + ) |
| 115 | + |
| 116 | + await self.profiles.create_index( |
| 117 | + [("oid", pymongo.ASCENDING), ("url", pymongo.ASCENDING)], |
| 118 | + collation=case_insensitive_collation, |
| 119 | + ) |
| 120 | + |
| 121 | + await self.profiles.create_index( |
| 122 | + [("oid", pymongo.ASCENDING), ("created", pymongo.ASCENDING)] |
| 123 | + ) |
| 124 | + |
| 125 | + await self.profiles.create_index( |
| 126 | + [("oid", pymongo.ASCENDING), ("modified", pymongo.ASCENDING)] |
| 127 | + ) |
| 128 | + |
109 | 129 | async def create_new_browser( |
110 | 130 | self, org: Organization, user: User, profile_launch: ProfileLaunchBrowserIn |
111 | 131 | ) -> BrowserId: |
@@ -415,7 +435,7 @@ async def update_profile_from_crawl_upload( |
415 | 435 | "modifiedCrawlCid": cid, |
416 | 436 | } |
417 | 437 | }, |
418 | | - return_document=ReturnDocument.BEFORE, |
| 438 | + return_document=pymongo.ReturnDocument.BEFORE, |
419 | 439 | ) |
420 | 440 | if not res: |
421 | 441 | return False |
@@ -494,7 +514,9 @@ async def list_profiles( |
494 | 514 | ] |
495 | 515 | ) |
496 | 516 |
|
497 | | - cursor = self.profiles.aggregate(aggregate) |
| 517 | + cursor = self.profiles.aggregate( |
| 518 | + aggregate, collation=case_insensitive_collation |
| 519 | + ) |
498 | 520 | results = await cursor.to_list(length=1) |
499 | 521 | result = results[0] |
500 | 522 | items = result["items"] |
|
0 commit comments