Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up publication queries #278

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 34 additions & 30 deletions tigaserver_app/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List, Dict

from rest_framework import viewsets
from rest_framework import status
from rest_framework.decorators import api_view
Expand Down Expand Up @@ -1052,38 +1054,30 @@
return True
return False

def get_cfa_reports():
new_reports_unfiltered_adults = get_reports_unfiltered_adults()
unfiltered_clean_reports = filter_reports(new_reports_unfiltered_adults, False)
unfiltered_clean_reports_id = [report.version_UUID for report in unfiltered_clean_reports]
unfiltered_clean_reports_query = Report.objects.filter(version_UUID__in=unfiltered_clean_reports_id).exclude(
hide=True)
# there seems to be some kind of caching issue .all() forces the queryset to refresh
results = []
for report in unfiltered_clean_reports_query:
results.append({"version_UUID": report.version_UUID})
return results
def get_cfa_reports() -> List[Dict[str, str]]:
new_reports_unfiltered_adults = get_reports_unfiltered_adults().filter(

Check warning on line 1058 in tigaserver_app/views.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/views.py#L1058

Added line #L1058 was not covered by tests
hide=False
).non_deleted()
return list(new_reports_unfiltered_adults.values('version_UUID'))

Check warning on line 1061 in tigaserver_app/views.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/views.py#L1061

Added line #L1061 was not covered by tests

@api_view(['GET'])
def force_refresh_cfa_reports(request):
if request.method == 'GET':
results = get_cfa_reports()
return Response(results)

def get_cfs_reports():
reports_imbornal = get_reports_imbornal()
new_reports_unfiltered_sites_embornal = get_reports_unfiltered_sites_embornal(reports_imbornal)
new_reports_unfiltered_sites_other = get_reports_unfiltered_sites_other(reports_imbornal)
new_reports_unfiltered_sites = new_reports_unfiltered_sites_embornal | new_reports_unfiltered_sites_other
unfiltered_clean_reports = filter_reports(new_reports_unfiltered_sites, False)
unfiltered_clean_reports_id = [report.version_UUID for report in unfiltered_clean_reports]
unfiltered_clean_reports_query = Report.objects.filter(version_UUID__in=unfiltered_clean_reports_id).exclude(
hide=True)
# there seems to be some kind of caching issue .all() forces the queryset to refresh
results = []
for report in unfiltered_clean_reports_query:
results.append({"version_UUID": report.version_UUID})
return results
def get_cfs_reports() -> List[Dict[str, str]]:
new_reports_unfiltered_sites = Report.objects.annotate(

Check warning on line 1070 in tigaserver_app/views.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/views.py#L1070

Added line #L1070 was not covered by tests
n_annotations=Count('expert_report_annotations')
).filter(
type=Report.TYPE_SITE,
n_annotations=0
).exclude(
Q(note__icontains='#345') |
Q(hide=True)
).has_photos().non_deleted()

return list(new_reports_unfiltered_sites.values('version_UUID'))

Check warning on line 1080 in tigaserver_app/views.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/views.py#L1080

Added line #L1080 was not covered by tests

@api_view(['GET'])
def force_refresh_cfs_reports(request):
Expand Down Expand Up @@ -1963,11 +1957,21 @@
#return Response(serializer.data)

# this function can be called by scripts and replicates the api behaviour, without calling API. Therefore, no timeouts
def all_reports_internal(year):
non_visible_report_id = [report.version_UUID for report in Report.objects.all() if not report.visible]
queryset = Report.objects.exclude(hide=True).exclude(type='mission').exclude(
version_UUID__in=non_visible_report_id).filter( package_filter )\
.exclude(package_name='ceab.movelab.tigatrapp', package_version=10).filter(creation_time__year=year)
def all_reports_internal(year: int):
visible_report_id = [

Check warning on line 1961 in tigaserver_app/views.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/views.py#L1961

Added line #L1961 was not covered by tests
report.pk for report in Report.objects.filter(
server_upload_time__year=year,
hide=False
).filter(
package_filter
).exclude(
Q(type='mission') | # Exclude mission reports
(Q(package_name='ceab.movelab.tigatrapp') & Q(package_version=10)) # Exclude specific package conditions
).iterator() if report.visible
]
queryset = Report.objects.filter(

Check warning on line 1972 in tigaserver_app/views.py

View check run for this annotation

Codecov / codecov/patch

tigaserver_app/views.py#L1972

Added line #L1972 was not covered by tests
pk__in=visible_report_id,
)
serializer = MapDataSerializer(queryset, many=True)
return serializer.data

Expand Down
Loading