Commit aaf6c682 authored by sim's avatar sim

[FIX] Factorize, optimize and fix scan_gargantext_and_delete

parent 238e6543
...@@ -16,7 +16,7 @@ django.setup() ...@@ -16,7 +16,7 @@ django.setup()
from gargantext.constants import QUERY_SIZE_N_MAX, get_resource, get_resource_by_name from gargantext.constants import QUERY_SIZE_N_MAX, get_resource, get_resource_by_name
from gargantext.models import Node, ProjectNode, DocumentNode from gargantext.models import Node, ProjectNode, DocumentNode
from gargantext.util.db import session, get_engine from gargantext.util.db import session, get_engine, func
from collections import Counter from collections import Counter
import importlib import importlib
from django.http import Http404 from django.http import Http404
...@@ -53,19 +53,24 @@ def scan_hal(request): ...@@ -53,19 +53,24 @@ def scan_hal(request):
return hal.scan_results(request) return hal.scan_results(request)
def scan_gargantext(corpus_id, request): def _search_docs(corpus_id, request):
return (session.query(DocumentNode) return (session.query(DocumentNode)
.filter_by(parent_id=corpus_id) .filter_by(parent_id=corpus_id)
.filter(Node.title_abstract.match(request)) .filter(Node.title_abstract.match(request)))
.count())
def scan_gargantext(corpus_id, request):
return (_search_docs(corpus_id, request)
.with_entities(func.count(DocumentNode.id.distinct()))
.one())[0]
def scan_gargantext_and_delete(corpus_id, request): def scan_gargantext_and_delete(corpus_id, request):
return (session.query(DocumentNode) r = _search_docs(corpus_id, request).delete(synchronize_session='fetch')
.filter_by(parent_id=corpus_id) session.commit()
.filter(Node.title_abstract.match(request))
.delete(synchronize_session='fetch') return r
)
def myProject_fromUrl(url): def myProject_fromUrl(url):
""" """
......
Markdown is supported
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