SciPost Code Repository
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SciPost
Manage
Activity
Members
Labels
Plan
Issues
118
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SciPost
SciPost
Commits
95dfb5c7
Commit
95dfb5c7
authored
6 years ago
by
Boris Ponsioen
Browse files
Options
Downloads
Patches
Plain Diff
Disables pagination in metacore for empty query: seems to be much faster
parent
897e73c9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
metacore/services.py
+18
-24
18 additions, 24 deletions
metacore/services.py
metacore/views.py
+17
-1
17 additions, 1 deletion
metacore/views.py
with
35 additions
and
25 deletions
metacore/services.py
+
18
−
24
View file @
95dfb5c7
...
@@ -30,31 +30,25 @@ def get_crossref_test(cursor='*'):
...
@@ -30,31 +30,25 @@ def get_crossref_test(cursor='*'):
params
=
{
'
cursor
'
:
cursor
,
'
rows
'
:
rows
,
'
mailto
'
:
'
b.g.t.ponsioen@uva.nl
'
}
params
=
{
'
cursor
'
:
cursor
,
'
rows
'
:
rows
,
'
mailto
'
:
'
b.g.t.ponsioen@uva.nl
'
}
last_cursor
=
cursor
last_cursor
=
cursor
for
j
in
range
(
0
,
2
):
r
=
requests
.
get
(
url
,
params
=
params
)
r
=
requests
.
get
(
url
,
params
=
params
)
r_json
=
r
.
json
()
r_json
=
r
.
json
()
citables_json
=
r_json
[
'
message
'
][
'
items
'
]
citables_json
=
r_json
[
'
message
'
][
'
items
'
]
cursor
=
r_json
[
'
message
'
][
'
next-cursor
'
]
cursor
=
r_json
[
'
message
'
][
'
next-cursor
'
]
number_of_results
=
len
(
r_json
[
'
message
'
][
'
items
'
])
number_of_results
=
len
(
r_json
[
'
message
'
][
'
items
'
])
citables
=
[
parse_crossref_citable
(
it
)
for
it
in
citables_json
]
citables
=
[
parse_crossref_citable
(
it
)
for
it
in
citables_json
]
# Parser returns None if there's an error
# Parser returns None if there's an error
errors
=
any
([
not
i
for
i
in
citables
if
i
==
False
])
errors
=
any
([
not
i
for
i
in
citables
if
i
==
False
])
orig_citables
=
citables
orig_citables
=
citables
citables
=
[
citable
for
citable
in
citables
if
citable
]
citables
=
[
citable
for
citable
in
citables
if
citable
]
# Mass insert in database (will fail on encountering existing documents
# Mass insert in database (will fail on encountering existing documents
# with same DOI
# with same DOI
if
citables
:
if
citables
:
Citable
.
objects
.
insert
(
citables
)
Citable
.
objects
.
insert
(
citables
)
break
elif
errors
:
print
(
"
Trying again
"
)
else
:
break
citable
=
[]
citable
=
[]
if
number_of_results
<
rows
:
if
number_of_results
<
rows
:
print
(
number_of_results
)
print
(
number_of_results
)
...
...
This diff is collapsed.
Click to expand it.
metacore/views.py
+
17
−
1
View file @
95dfb5c7
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.views.generic.list
import
ListView
from
django.views.generic.list
import
ListView
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.core.paginator
import
Paginator
from
.models
import
Citable
from
.models
import
Citable
from
.forms
import
CitableSearchForm
from
.forms
import
CitableSearchForm
...
@@ -19,7 +20,7 @@ class CitableListView(ListView):
...
@@ -19,7 +20,7 @@ class CitableListView(ListView):
queryset
=
self
.
form
.
search_results
()
queryset
=
self
.
form
.
search_results
()
else
:
else
:
# queryset = Citable.objects.simple().limit(100)
# queryset = Citable.objects.simple().limit(100)
queryset
=
Citable
.
objects
.
simple
().
order_by
(
'
-metadata.is-referenced-by-count
'
)
queryset
=
Citable
.
objects
.
simple
().
order_by
(
'
-metadata.is-referenced-by-count
'
)
.
limit
(
10
)
return
queryset
return
queryset
...
@@ -36,3 +37,18 @@ class CitableListView(ListView):
...
@@ -36,3 +37,18 @@ class CitableListView(ListView):
context
[
'
browse
'
]
=
True
context
[
'
browse
'
]
=
True
return
context
return
context
def
get_paginate_by
(
self
,
queryset
):
"""
Dynamically compute pagination setting.
Can be used to disable pagination on
'
empty
'
search -> manually doing .limit(N) seems
to be much faster with mongoengine than Django
'
s pagination
Also you can add an extra parameter to specify pagination size, like so:
return self.request.GET.get(
'
paginate_by
'
, self.paginate_by)
"""
if
self
.
request
.
GET
:
return
self
.
paginate_by
else
:
return
None
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment