From 1a4822d6bec34c7d87ec0d315adda4c331963b90 Mon Sep 17 00:00:00 2001 From: Stephen Hu <812791840@qq.com> Date: Thu, 18 Dec 2025 09:40:33 +0800 Subject: [PATCH] Refactor: Improve the timestamp consistency (#11942) ### What problem does this PR solve? Improve the timestamp consistency ### Type of change - [x] Refactoring --- api/db/services/common_service.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/api/db/services/common_service.py b/api/db/services/common_service.py index 5b906b5a8..60db241cc 100644 --- a/api/db/services/common_service.py +++ b/api/db/services/common_service.py @@ -169,10 +169,12 @@ class CommonService: """ if "id" not in kwargs: kwargs["id"] = get_uuid() - kwargs["create_time"] = current_timestamp() - kwargs["create_date"] = datetime_format(datetime.now()) - kwargs["update_time"] = current_timestamp() - kwargs["update_date"] = datetime_format(datetime.now()) + timestamp = current_timestamp() + cur_datetime = datetime_format(datetime.now()) + kwargs["create_time"] = timestamp + kwargs["create_date"] = cur_datetime + kwargs["update_time"] = timestamp + kwargs["update_date"] = cur_datetime sample_obj = cls.model(**kwargs).save(force_insert=True) return sample_obj @@ -207,10 +209,14 @@ class CommonService: data_list (list): List of dictionaries containing record data to update. Each dictionary must include an 'id' field. """ + + timestamp = current_timestamp() + cur_datetime = datetime_format(datetime.now()) + for data in data_list: + data["update_time"] = timestamp + data["update_date"] = cur_datetime with DB.atomic(): for data in data_list: - data["update_time"] = current_timestamp() - data["update_date"] = datetime_format(datetime.now()) cls.model.update(data).where(cls.model.id == data["id"]).execute() @classmethod