fix(admin): resolve latest job selection by effective timestamp
This commit is contained in:
@@ -2,6 +2,8 @@ from apps.core.models import BackgroundJob
|
||||
from apps.core.services import BackgroundJobService
|
||||
from django.contrib.auth import authenticate, get_user_model
|
||||
from django.contrib.auth.hashers import check_password
|
||||
from django.db.models import F
|
||||
from django.db.models.functions import Coalesce
|
||||
from drf_yasg import openapi
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
from rest_framework import generics, status
|
||||
@@ -249,7 +251,14 @@ class AdminUsersManagementView(APIView):
|
||||
latest_jobs: dict[int, BackgroundJob] = {}
|
||||
jobs = BackgroundJobService.get_queryset().filter(
|
||||
user_id__in=user_ids
|
||||
).order_by("user_id", "-created_at")
|
||||
).annotate(
|
||||
_effective_job_ts=Coalesce(
|
||||
F("completed_at"),
|
||||
F("started_at"),
|
||||
F("updated_at"),
|
||||
F("created_at"),
|
||||
)
|
||||
).order_by("user_id", "-_effective_job_ts")
|
||||
|
||||
for job in jobs:
|
||||
if job.user_id not in latest_jobs:
|
||||
|
||||
Reference in New Issue
Block a user