Ensure that search doesn't make extra SQL lookups
Before this change, we were accessing the `.kind` on the repository object, which caused peewee to make an extra lookup for each result
This commit is contained in:
parent
9d97e053b3
commit
227aa8ab8c
2 changed files with 33 additions and 9 deletions
|
@ -1,12 +1,35 @@
|
|||
from endpoints.api.search import ConductRepositorySearch
|
||||
import pytest
|
||||
|
||||
from playhouse.test_utils import assert_query_count
|
||||
|
||||
from data.model import _basequery
|
||||
from endpoints.api.search import ConductRepositorySearch, ConductSearch
|
||||
from endpoints.api.test.shared import client_with_identity, conduct_api_call
|
||||
from test.fixtures import *
|
||||
|
||||
def test_repository_search(client):
|
||||
@pytest.mark.parametrize('query, expected_query_count', [
|
||||
('simple', 7),
|
||||
('public', 6),
|
||||
('repository', 6),
|
||||
])
|
||||
def test_repository_search(query, expected_query_count, client):
|
||||
with client_with_identity('devtable', client) as cl:
|
||||
params = {'query': 'simple'}
|
||||
result = conduct_api_call(cl, ConductRepositorySearch, 'GET', params, None, 200).json
|
||||
assert not result['has_additional']
|
||||
assert result['start_index'] == 0
|
||||
assert result['page'] == 1
|
||||
assert result['results'][0]['name'] == 'simple'
|
||||
params = {'query': query}
|
||||
with assert_query_count(expected_query_count):
|
||||
result = conduct_api_call(cl, ConductRepositorySearch, 'GET', params, None, 200).json
|
||||
assert result['start_index'] == 0
|
||||
assert result['page'] == 1
|
||||
assert len(result['results'])
|
||||
|
||||
|
||||
@pytest.mark.parametrize('query, expected_query_count', [
|
||||
('simple', 8),
|
||||
('public', 8),
|
||||
('repository', 8),
|
||||
])
|
||||
def test_search_query_count(query, expected_query_count, client):
|
||||
with client_with_identity('devtable', client) as cl:
|
||||
params = {'query': query}
|
||||
with assert_query_count(expected_query_count):
|
||||
result = conduct_api_call(cl, ConductSearch, 'GET', params, None, 200).json
|
||||
assert len(result['results'])
|
||||
|
|
Reference in a new issue