Commit d7ea4910 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

Merge branch '91-browse-page-gene-list' into 'dev'

Browse trough pages on gene list

Closes #91

See merge request !51
parents 59daf1d6 8d64df33
Pipeline #31567 passed with stages
in 3 minutes and 13 seconds
......@@ -40,10 +40,13 @@ test-backend:
image: $CI_REGISTRY_IMAGE/backend:${CI_COMMIT_REF_NAME}
services:
- postgres:11.4
- redis:alpine
stage: test
variables:
DATABASE_HOST: localhost
DJANGO_SETTINGS_MODULE: "metagenedb.settings-gitlab-ci"
REDIS_HOST: "localhost"
CACHE_TTL: "0"
script:
- apt-get install -y postgresql-client
- cd backend
......
from rest_framework.pagination import PageNumberPagination
from metagenedb.common.django_default.paginator import CachedCountPaginator
class DefaultPageNumberPagination(PageNumberPagination):
django_paginator_class = CachedCountPaginator
page_size_query_param = 'page_size'
max_page_size = 5000
import hashlib
import inspect
from django.conf import settings
from django.core.cache import cache
from django.core.cache.backends.base import DEFAULT_TIMEOUT
from django.core.paginator import Paginator
from django.utils.functional import cached_property
from django.utils.inspect import method_has_no_args
CACHE_TTL = getattr(settings, 'CACHE_TTL', DEFAULT_TIMEOUT)
class CachedCountPaginator(Paginator):
@cached_property
def count(self):
"""Return the total number of objects, across all pages."""
# Create has from SQL query for REDIS cache
hash_object = hashlib.md5(str(self.object_list.query).encode('utf-8'))
redis_key = hash_object.hexdigest()
if redis_key in cache:
return cache.get(redis_key)
else:
c = getattr(self.object_list, 'count', None)
if callable(c) and not inspect.isbuiltin(c) and method_has_no_args(c):
count = c()
else:
count = len(self.object_list)
cache.set(redis_key, count, timeout=CACHE_TTL)
return count
......@@ -21,6 +21,8 @@ CACHES = {
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient"
},
"KEY_PREFIX": "example"
"KEY_PREFIX": "metagenedb"
}
}
# Time in seconds for
CACHE_TTL = int(os.getenv('CACHE_TTL', 600))
......@@ -21,8 +21,8 @@ kubectl create secret generic backend-cron-credentials -n ${NAMESPACE} --from-li
envsubst < ci/kubernetes/postgresql.yaml | kubectl apply -n ${NAMESPACE} -f -
kubectl -n ${NAMESPACE} wait --for=condition=available --timeout=600s deployment/postgresql
## Redis
# envsubst < ci/kubernetes/redis.yaml | kubectl apply -n ${NAMESPACE} -f -
# kubectl -n ${NAMESPACE} wait --for=condition=available --timeout=600s deployment/redis
envsubst < ci/kubernetes/redis.yaml | kubectl apply -n ${NAMESPACE} -f -
kubectl -n ${NAMESPACE} wait --for=condition=available --timeout=600s deployment/redis
## Backend
envsubst < ci/kubernetes/backend.yaml | kubectl apply -n ${NAMESPACE} -f -
kubectl -n ${NAMESPACE} patch deployment backend -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"`date +'%s'`\"}}}}}"
......
......@@ -45,6 +45,8 @@ spec:
key: secret_key
- name: REDIS_HOST
value: redis
- name: REDIS_PORT
value: '6379'
- name: PORT
value: "8000"
- name: DEBUG
......
......@@ -64,6 +64,8 @@ services:
redis:
image: redis:alpine
container_name: redis
ports:
- "6379:6379"
networks:
- main
......
......@@ -179,7 +179,7 @@
</v-btn>
<v-btn
color="secondary lighten-1"
@click="runSearch"
@click="runNewSearch"
>
Apply<v-icon right>far fa-check-square</v-icon>
</v-btn>
......@@ -231,8 +231,16 @@
</template>
</v-data-table>
</v-list>
<v-card class="white" flat>
<v-subheader class="text-right">{{count}} genes found</v-subheader>
<v-card flat>
<div class="text-xs-center" v-if="count">
<v-pagination
v-model="pageNumber"
:length="pageTotalNumber"
:total-visible="7"
@input="getGenes"
></v-pagination>
</div>
<v-subheader>{{count}} genes found</v-subheader>
</v-card>
</v-flex>
</v-layout>
......
......@@ -7,10 +7,11 @@ export default {
genes: [],
count: 0,
page: 1,
page_size: 20,
// pagination
pagination: {
rowsPerPage: 20,
},
pageNumber: 1,
// Filters
// - Gene info
geneSource: 'all',
......@@ -58,7 +59,10 @@ export default {
return [this.page_size];
},
qParams() {
const qParams = { page_size: this.page_size };
const qParams = {
page_size: this.pagination.rowsPerPage,
page: this.pageNumber
};
if (this.geneSource && this.geneSource != 'all') {
qParams.source = this.geneSource
}
......@@ -86,6 +90,12 @@ export default {
taxChoices() {
return Object.keys(this.taxItems).sort();
},
pageTotalNumber() {
if ((this.count % this.pagination.rowsPerPage) > 0) {
return Math.floor(this.count/this.pagination.rowsPerPage) + 1;
}
return Math.floor(this.count/this.pagination.rowsPerPage);
}
},
mounted() {
this.getGenes();
......@@ -176,8 +186,9 @@ export default {
}
this.getTaxoPresence();
},
runSearch() {
runNewSearch() {
this.requestDone = false;
this.pageNumber = 1;
this.getGenes();
},
},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment