mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-30 07:06:39 +08:00
feature: add system setting service (#12408)
### What problem does this PR solve? #12409 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@ -190,10 +190,15 @@ class CommonService:
|
||||
data_list (list): List of dictionaries containing record data to insert.
|
||||
batch_size (int, optional): Number of records to insert in each batch. Defaults to 100.
|
||||
"""
|
||||
current_ts = current_timestamp()
|
||||
current_datetime = datetime_format(datetime.now())
|
||||
with DB.atomic():
|
||||
for d in data_list:
|
||||
d["create_time"] = current_timestamp()
|
||||
d["create_date"] = datetime_format(datetime.now())
|
||||
d["create_time"] = current_ts
|
||||
d["create_date"] = current_datetime
|
||||
d["update_time"] = current_ts
|
||||
d["update_date"] = current_datetime
|
||||
|
||||
for i in range(0, len(data_list), batch_size):
|
||||
cls.model.insert_many(data_list[i : i + batch_size]).execute()
|
||||
|
||||
|
||||
44
api/db/services/system_settings_service.py
Normal file
44
api/db/services/system_settings_service.py
Normal file
@ -0,0 +1,44 @@
|
||||
#
|
||||
# Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
from datetime import datetime
|
||||
from common.time_utils import current_timestamp, datetime_format
|
||||
from api.db.db_models import DB
|
||||
from api.db.db_models import SystemSettings
|
||||
from api.db.services.common_service import CommonService
|
||||
|
||||
|
||||
class SystemSettingsService(CommonService):
|
||||
model = SystemSettings
|
||||
|
||||
@classmethod
|
||||
@DB.connection_context()
|
||||
def get_by_name(cls, name):
|
||||
objs = cls.model.select().where(cls.model.name.startswith(name))
|
||||
return objs
|
||||
|
||||
@classmethod
|
||||
@DB.connection_context()
|
||||
def update_by_name(cls, name, obj):
|
||||
obj["update_time"] = current_timestamp()
|
||||
obj["update_date"] = datetime_format(datetime.now())
|
||||
cls.model.update(obj).where(cls.model.name.startswith(name)).execute()
|
||||
return SystemSettings(**obj)
|
||||
|
||||
@classmethod
|
||||
@DB.connection_context()
|
||||
def get_record_count(cls):
|
||||
count = cls.model.select().count()
|
||||
return count
|
||||
Reference in New Issue
Block a user