Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Carlos Ribas
rnacentral-webcode
Commits
17aa3e52
Commit
17aa3e52
authored
May 26, 2021
by
carlosribas
Browse files
Create class to avoid large table count query
parent
53e4d888
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
0 deletions
+24
-0
rnacentral/rnacentral/utils/pagination.py
rnacentral/rnacentral/utils/pagination.py
+24
-0
No files found.
rnacentral/rnacentral/utils/pagination.py
View file @
17aa3e52
import
sys
from
django.core.paginator
import
Paginator
from
django.db.models.query
import
RawQuerySet
from
django.db.models
import
sql
from
django.utils.functional
import
cached_property
from
rest_framework.pagination
import
PageNumberPagination
from
rest_framework.response
import
Response
class
CustomPaginatorClass
(
Paginator
):
"""Use a large number to make sure that all results can be shown"""
@
cached_property
def
count
(
self
):
return
sys
.
maxsize
class
LargeTablePagination
(
PageNumberPagination
):
"""Use this paginator class to avoid large table count query"""
django_paginator_class
=
CustomPaginatorClass
def
get_paginated_response
(
self
,
data
):
return
Response
({
'next'
:
self
.
get_next_link
(),
'previous'
:
self
.
get_previous_link
(),
'results'
:
data
})
class
Pagination
(
PageNumberPagination
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment