diff --git a/service/admin.py b/service/admin.py index 11aa77d..f579e59 100644 --- a/service/admin.py +++ b/service/admin.py @@ -67,6 +67,7 @@ class CategoryAdmin(admin.ModelAdmin): class PostPvzCategoryAdmin(CategoryAdmin): def save_model(self, request, obj, form, change): obj.save() + run_psql_command() if 'include_in_ml' in form.changed_data or 'visible' in form.changed_data: LayerService.update_categories(obj) cache.clear() @@ -92,9 +93,8 @@ class GroupAdmin(admin.ModelAdmin): class PostPvzGroupAdmin(GroupAdmin): def save_model(self, request, obj, form, change): - if not obj.pk: - run_psql_command() obj.save() + run_psql_command() if 'include_in_ml' in form.changed_data or 'visible' in form.changed_data: LayerService.update_groups(obj) cache.clear() diff --git a/service/tasks.py b/service/tasks.py index aaed630..feb9a66 100644 --- a/service/tasks.py +++ b/service/tasks.py @@ -25,10 +25,11 @@ from io import StringIO from django.core.cache import cache from service.layer_service import LayerService from service.service import PointService +from service.utils import run_psql_command @shared_task() -def raschet(table_name='service_placementpoint'): +def raschet(table_name='service_placementpoint', need_time=True): print('start raschet') status, _ = models.TaskStatus.objects.get_or_create(task_name=STATUS_TASK_NAME) raschet_objs = models.RaschetObjects.objects.all() @@ -319,10 +320,13 @@ def raschet(table_name='service_placementpoint'): conn2.close() cache.clear() log_to_telegram('end raschet') - status.status = 'Перерасчет ML завершен' - status.save() - LastMLCall.objects.all().delete() - LastMLCall.objects.create() + run_psql_command() + status.status = 'Перерасчет ML завершен' + status.save() + if need_time: + LastMLCall.objects.all().delete() + LastMLCall.objects.create() + @shared_task diff --git a/service/utils.py b/service/utils.py index 086e872..9f6c887 100644 --- a/service/utils.py +++ b/service/utils.py @@ -24,7 +24,7 @@ def run_psql_command(): ) try: cursor = connection.cursor() - command = "CALL public.pivot_dist();" + command = "CALL public.pivot_dist();CALL public.prepivot_dist();" cursor.execute(command) connection.commit() except psycopg2.Error as e: diff --git a/service/views.py b/service/views.py index f12423e..53de5be 100644 --- a/service/views.py +++ b/service/views.py @@ -367,7 +367,7 @@ class PrePlacementPointViewSet(PlacementPointViewSet): file_id = request.POST['id'] total, matched, problem = PointService().start_mathing(file_id) PointService().make_enrichment() - raschet('service_preplacementpoint') + raschet('service_preplacementpoint', need_time=False) return Response( {'message': {'total': total, 'matched': matched, 'error': problem, 'unmatched': total - matched - problem}}, status=HTTPStatus.OK,