perf: operate record

This commit is contained in:
feng
2025-06-27 18:59:58 +08:00
committed by ZhaoJiSen
parent 76c6ed0f95
commit a238c5d34b
4 changed files with 16 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
import copy
from datetime import datetime
from itertools import chain
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.core.exceptions import ObjectDoesNotExist
@@ -7,7 +8,6 @@ from django.db import models
from django.db.models import F, Value, CharField
from django.db.models.functions import Concat
from django.utils import translation
from itertools import chain
from common.db.fields import RelatedManager
from common.utils import validate_ip, get_ip_city, get_logger
@@ -16,7 +16,6 @@ from .const import DEFAULT_CITY, ActivityChoices as LogChoice
from .handler import create_or_update_operate_log
from .models import ActivityLog
logger = get_logger(__name__)
@@ -151,7 +150,7 @@ def record_operate_log_and_activity_log(ids, action, detail, model, **kwargs):
org_id = current_org.id
with translation.override('en'):
resource_type = model._meta.verbose_name
resource_type = kwargs.pop('resource_type', None) or model._meta.verbose_name
create_or_update_operate_log(action, resource_type, force=True, **kwargs)
base_data = {'type': LogChoice.operate_log, 'detail': detail, 'org_id': org_id}
activities = [ActivityLog(resource_id=r_id, **base_data) for r_id in ids]