Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
Choose a Base Repository
hypothesis/h
40a/h
AFDudley/h
BigBlueHat/h
BinaryStars/h
CCH543/h
Cinemacloud/h
Ericgood/h
FTG-003/h
Forethinker/h
GratefulTony/h
HGldJ1966/h
JJediny/h
John-Williams/h
Laurian/h
LittleFancy/h
MattyQ/h
Mishkin2015/h
RichardLitt/h
Staffan1/h
SteelWagstaff/h
TowerBR/h
VanyTang/h
abigailricarte/h
ackermann/h
alecchap/h
alesarrett/h
alexsegura/h
almereyda/h
alon/h
andzi/h
angelicxsoul/h
ansmoh/h
apurvajalit/h
arjunvasan/h
asdevor/h
bZichett/h
badgettrg/Webmarks
balmas/h
balupton/h
bbarker/h
bennlich/h
benthor/h
blakewest/h
bogste/h
bradparks/h
brittanystoroz/h
buiquangchien/h
cdchapman/h
charblanc/h
chowsamihq/h
chr7stos/Webmarks
chrber/h
chrismPssina/h
christinaphamAD/h
cmbirk/h
codeaudit/h
coolcool21/h
cove/h
csillag/h
danjimilk/h
dannyhope/h
daredream/h
davidmcclure/h
dennisplucinik/h
dezynetechnologies/h
diegodlh/h
djcun95/h
donsequitur/h
edsu/h
eiro10/h
emckean/h
ercchy/h
eshellman/h
fangang123/h
fchasen/h
fcrimins/h
fhirsch/h
ficolo/h
fragkopoulos/h
gauravkeerthi/h
geass/h
gergely-ujvari/h
gitter-badger/h
gnott/h
gobengo/h
gorinovic/h
gus3000/h
hashin/h
helemaalbigt/h
hmstepanek/h
hwasiti/h
hylhero/h
hyperstudio/h
iHDeveloper/h
imeysam/h
jackspaceBerkeley/h
jarey/h
jasdeep/h
jason790/h
jasonzou/j
jazahn/h
jccr/h
jean/h
jeka57/h
jeremydean/h
jermnelson/h
jibe-b/h
jnishiyama/h
jojksd/h
jpadilla/h
jtremback/h
judell/h
juli-so/h
kabacs/h
karissa/h
kaushikvijay/h
kaydoh/h
kill4uk/h
klopiinas/h
klrkdekira/h
koulihong311/h
krassif/h
krstnkngs/h
leoqmp/h
linhua55/h
lucadealfaro/h
lyspooner/h
lyzadanger/h
m1yag1/h
magee/h
mambocab/h
manunymous/h
maraino/h
mari-ja/h
markbarratt/h
martinq/h
mbbaig/h
mcarv63/h
meawoppl/h
meflyup/h
metasj/h
mgasner/h
mgax/h
mollycr/h
mrchrisadams/h
mrienstra/h
mshavlovsky/h
muddasani/h
nagyist/hyphothesis-h
nagyistoce/hypothesis-h
nanxio/h
neozhangthe1/h
ningyifan/h
nkingsley/h
nlholdem/h
nlisgo/h
noscripter/h
nshkuro/h
odnodn/h
oliversauter/h
openbizgit/h
opengovfoundation/h
openstax/hypothesis-server
ouroboros8/h
pablomarti/h
pamo/h
philipn/h
philschatz/h
pinballwonder/h
plainspace/h
raowl/h
rickyhan/h
rmoorman/h
rmtsukuru/h
robertknight/h
rowhit/h
rsarxiv/h
saakaifoundry/h
samrose/h
scharf/h
shepazu/h
sherah/h
shofheinz/h
soapdog/h
ssin122/test-h
st-fresh/h
stuk88/h
sylvanmist/h
tetratorus/h
tilgovi/h
tomnar/h
trivenews/h
truthadjustr/h
utngz/h
voidfiles/h
wenchen/h
yargevad/h
yumatch/h
zshen777/h
Nothing to show
Choose a Head Repository
hypothesis/h
40a/h
AFDudley/h
BigBlueHat/h
BinaryStars/h
CCH543/h
Cinemacloud/h
Ericgood/h
FTG-003/h
Forethinker/h
GratefulTony/h
HGldJ1966/h
JJediny/h
John-Williams/h
Laurian/h
LittleFancy/h
MattyQ/h
Mishkin2015/h
RichardLitt/h
Staffan1/h
SteelWagstaff/h
TowerBR/h
VanyTang/h
abigailricarte/h
ackermann/h
alecchap/h
alesarrett/h
alexsegura/h
almereyda/h
alon/h
andzi/h
angelicxsoul/h
ansmoh/h
apurvajalit/h
arjunvasan/h
asdevor/h
bZichett/h
badgettrg/Webmarks
balmas/h
balupton/h
bbarker/h
bennlich/h
benthor/h
blakewest/h
bogste/h
bradparks/h
brittanystoroz/h
buiquangchien/h
cdchapman/h
charblanc/h
chowsamihq/h
chr7stos/Webmarks
chrber/h
chrismPssina/h
christinaphamAD/h
cmbirk/h
codeaudit/h
coolcool21/h
cove/h
csillag/h
danjimilk/h
dannyhope/h
daredream/h
davidmcclure/h
dennisplucinik/h
dezynetechnologies/h
diegodlh/h
djcun95/h
donsequitur/h
edsu/h
eiro10/h
emckean/h
ercchy/h
eshellman/h
fangang123/h
fchasen/h
fcrimins/h
fhirsch/h
ficolo/h
fragkopoulos/h
gauravkeerthi/h
geass/h
gergely-ujvari/h
gitter-badger/h
gnott/h
gobengo/h
gorinovic/h
gus3000/h
hashin/h
helemaalbigt/h
hmstepanek/h
hwasiti/h
hylhero/h
hyperstudio/h
iHDeveloper/h
imeysam/h
jackspaceBerkeley/h
jarey/h
jasdeep/h
jason790/h
jasonzou/j
jazahn/h
jccr/h
jean/h
jeka57/h
jeremydean/h
jermnelson/h
jibe-b/h
jnishiyama/h
jojksd/h
jpadilla/h
jtremback/h
judell/h
juli-so/h
kabacs/h
karissa/h
kaushikvijay/h
kaydoh/h
kill4uk/h
klopiinas/h
klrkdekira/h
koulihong311/h
krassif/h
krstnkngs/h
leoqmp/h
linhua55/h
lucadealfaro/h
lyspooner/h
lyzadanger/h
m1yag1/h
magee/h
mambocab/h
manunymous/h
maraino/h
mari-ja/h
markbarratt/h
martinq/h
mbbaig/h
mcarv63/h
meawoppl/h
meflyup/h
metasj/h
mgasner/h
mgax/h
mollycr/h
mrchrisadams/h
mrienstra/h
mshavlovsky/h
muddasani/h
nagyist/hyphothesis-h
nagyistoce/hypothesis-h
nanxio/h
neozhangthe1/h
ningyifan/h
nkingsley/h
nlholdem/h
nlisgo/h
noscripter/h
nshkuro/h
odnodn/h
oliversauter/h
openbizgit/h
opengovfoundation/h
openstax/hypothesis-server
ouroboros8/h
pablomarti/h
pamo/h
philipn/h
philschatz/h
pinballwonder/h
plainspace/h
raowl/h
rickyhan/h
rmoorman/h
rmtsukuru/h
robertknight/h
rowhit/h
rsarxiv/h
saakaifoundry/h
samrose/h
scharf/h
shepazu/h
sherah/h
shofheinz/h
soapdog/h
ssin122/test-h
st-fresh/h
stuk88/h
sylvanmist/h
tetratorus/h
tilgovi/h
tomnar/h
trivenews/h
truthadjustr/h
utngz/h
voidfiles/h
wenchen/h
yargevad/h
yumatch/h
zshen777/h
Nothing to show
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jul 03, 2015
Don't indent API output
This is an interface for machines, not humans. This results in a factor
of >2 speedup for large query sets:

Before:

    $ wrk -c1 -d10s -t1 'http://localhost:5000/api/search?limit=1000'
    Running 10s test @ http://localhost:5000/api/search?limit=1000
      1 threads and 1 connections
      Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency   340.54ms   38.82ms 446.64ms   75.86%
        Req/Sec     2.62      0.49     3.00     62.07%
      29 requests in 10.08s, 88.02MB read
    Requests/sec:      2.88
    Transfer/sec:      8.74MB

After:

    $ wrk -c1 -d10s -t1 'http://localhost:5000/api/search?limit=1000'
    Running 10s test @ http://localhost:5000/api/search?limit=1000
      1 threads and 1 connections
      Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency   167.97ms   25.03ms 223.00ms   69.49%
        Req/Sec     6.31      2.71    10.00     69.49%
      59 requests in 10.04s, 96.15MB read
    Requests/sec:      5.87
    Transfer/sec:      9.57MB
Don't make two queries when one will do.
The search function doesn't need to make two calls when one will do.
Lower default and maximum "limit" params for Atom feed
With a default timeout of 200ms for the API Client, retrieving and
parsing JSON for that many annotations takes too long.
Showing with 29 additions and 23 deletions.
  1. +7 −4 h/api/search.py
  2. +1 −1 h/app.py
  3. +14 −14 h/test/views_test.py
  4. +7 −4 h/views.py
View
@@ -124,10 +124,13 @@ def search(request_params, user=None):
request_params.get('uri'))
query = build_query(request_params)
results = models.Annotation.search_raw(query, user=user)
count = models.Annotation.search_raw(query, {'search_type': 'count'},
raw_result=True)
return {"rows": results, "total": count["hits"]["total"]}
results = models.Annotation.search_raw(query, user=user, raw_result=True)
total = results['hits']['total']
docs = results['hits']['hits']
rows = [models.Annotation(d['_source'], id=d['_id']) for d in docs]
return {"rows": rows, "total": total}
def index(user=None):
View
@@ -97,7 +97,7 @@ def create_api(global_config, **settings):
config.set_authorization_policy(acl_authz)
config.set_root_factory('h.api.resources.create_root')
config.add_renderer('json', JSON(indent=4))
config.add_renderer('json', JSON())
config.add_subscriber('h.api.subscribers.set_user_from_oauth',
'pyramid.events.ContextFound')
config.add_tween('h.api.tweens.auth_token')
View
@@ -170,16 +170,16 @@ def test_it_adds_a_limit_param_if_none_is_given(self):
views.stream_atom(request)
params = request.api_client.get.call_args[1]["params"]
assert params["limit"] == 1000
assert "limit" in params
def test_it_forwards_user_supplied_limits(self):
"""User-supplied ``limit`` params should be forwarded.
If the user supplies a ``limit`` param < 1000 this should be forwarded
If the user supplies a ``limit`` param < 500 this should be forwarded
to the search API.
"""
for limit in (0, 500, 1000):
for limit in (0, 250, 500):
request = mock.MagicMock()
request.params = {"limit": limit}
@@ -188,40 +188,40 @@ def test_it_forwards_user_supplied_limits(self):
params = request.api_client.get.call_args[1]["params"]
assert params["limit"] == limit
def test_it_ignores_limits_greater_than_1000(self):
"""It doesn't let the user specify a ``limit`` > 1000.
def test_it_ignores_limits_greater_than_500(self):
"""It doesn't let the user specify a ``limit`` > 500.
It just reduces the limit to 1000.
It just reduces the limit to 500.
"""
request = mock.MagicMock()
request.params = {"limit": 1001}
request.params = {"limit": 501}
views.stream_atom(request)
params = request.api_client.get.call_args[1]["params"]
assert params["limit"] == 1000
assert params["limit"] == 500
def test_it_falls_back_to_1000_if_limit_is_invalid(self):
"""If the user gives an invalid limit value it falls back to 1000."""
def test_it_falls_back_to_100_if_limit_is_invalid(self):
"""If the user gives an invalid limit value it falls back to 100."""
for limit in ("not a valid integer", None, [1, 2, 3]):
request = mock.MagicMock()
request.params = {"limit": limit}
views.stream_atom(request)
params = request.api_client.get.call_args[1]["params"]
assert params["limit"] == 1000
assert params["limit"] == 100
def test_it_falls_back_to_1000_if_limit_is_negative(self):
"""If given a negative number for limit it falls back to 1000."""
def test_it_falls_back_to_100_if_limit_is_negative(self):
"""If given a negative number for limit it falls back to 100."""
request = mock.MagicMock()
request.params = {"limit": -50}
views.stream_atom(request)
params = request.api_client.get.call_args[1]["params"]
assert params["limit"] == 1000
assert params["limit"] == 100
def test_it_forwards_url_params_to_the_api(self):
"""Any URL params are forwarded to the search API."""
View
@@ -153,14 +153,17 @@ def stream_atom(request):
params = dict(request.params)
# The maximum value that this function allows the limit param.
max_limit = 1000
default_limit = 100
max_limit = 500
try:
params["limit"] = int(params.get("limit", max_limit))
params["limit"] = int(params.get("limit", default_limit))
except (ValueError, TypeError):
params["limit"] = max_limit
params["limit"] = default_limit
if not 0 <= params["limit"] <= max_limit:
if params["limit"] < 0:
params["limit"] = default_limit
if params["limit"] > max_limit:
params["limit"] = max_limit
try:

No commit comments for this range