|
78 | 78 |
|
79 | 79 | logger = logging.getLogger(__name__) |
80 | 80 |
|
| 81 | +SCORE_SET_SEARCH_MAX_LIMIT = 100 |
| 82 | +SCORE_SET_SEARCH_MAX_PUBLICATION_IDENTIFIERS = 40 |
| 83 | + |
81 | 84 |
|
82 | 85 | async def fetch_score_set_by_urn( |
83 | 86 | db, urn: str, user: Optional[UserData], owner_or_contributor: Optional[UserData], only_published: bool |
@@ -152,14 +155,21 @@ def search_score_sets( |
152 | 155 | ) |
153 | 156 | search.published = True |
154 | 157 |
|
155 | | - # Require a limit of at most 100 when the search query does not include publication identifiers. We allow unlimited |
156 | | - # searches with publication identifiers, presuming that such a search will not have excessive results. |
157 | | - if search.publication_identifiers is None and (search.limit is None or search.limit > 100): |
158 | | - search.limit = 100 |
| 158 | + # Require a limit of at most SCORE_SET_SEARCH_MAX_LIMIT when the search query does not include publication |
| 159 | + # identifiers. We allow unlimited searches with publication identifiers, presuming that such a search will not have |
| 160 | + # excessive results. |
| 161 | + if search.publication_identifiers is None and (search.limit is None or search.limit > SCORE_SET_SEARCH_MAX_LIMIT): |
| 162 | + raise HTTPException( |
| 163 | + status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, |
| 164 | + detail=f"Cannot search for more than {SCORE_SET_SEARCH_MAX_LIMIT} score sets at a time. Please use the offset and limit parameters to run a paginated search.", |
| 165 | + ) |
159 | 166 |
|
160 | | - # Also limit the search to at most 40 publication identifiers, to prevent artificially constructed searches that |
161 | | - # return very large result sets. |
162 | | - if search.publication_identifiers is not None and len(search.publication_identifiers) > 40: |
| 167 | + # Also limit the search to at most SCORE_SET_SEARCH_MAX_PUBLICATION_IDENTIFIERS publication identifiers, to prevent |
| 168 | + # artificially constructed searches that return very large result sets. |
| 169 | + if ( |
| 170 | + search.publication_identifiers is not None |
| 171 | + and len(search.publication_identifiers) > SCORE_SET_SEARCH_MAX_PUBLICATION_IDENTIFIERS |
| 172 | + ): |
163 | 173 | raise HTTPException( |
164 | 174 | status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, |
165 | 175 | detail="Cannot search for score sets belonging to more than 40 publication identifiers at once.", |
|
0 commit comments