Skip to content

Commit

Permalink
feat: add the create_batch function for the repositoryDAO
Browse files Browse the repository at this point in the history
  • Loading branch information
xingwanying committed Dec 10, 2024
1 parent 57291dd commit 22e06a2
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions server/core/dao/repositoryConfigDAO.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import Counter, List
from core.dao.BaseDAO import BaseDAO
from core.models.bot import RepoBindBotConfigVO
from core.models.repository import RepositoryConfig
Expand Down Expand Up @@ -31,15 +31,41 @@ def create(self, data: RepositoryConfig):
def create_batch(self, data_list: List[RepositoryConfig]):
try:
records_data = [data.model_dump(exclude=["id"]) for data in data_list]
repo_config = (
self.client.from_("github_repo_config").insert(records_data).execute()
repo_ids = [data.repo_id for data in data_list]

# 查询现有的 repo_id
response = (
self.client.table("github_repo_config")
.select("repo_id")
.in_("repo_id", repo_ids)
.execute()
)
if repo_config:
return True, {
"message": "GithubRepoConfig records created successfully"
existing_repo_ids = (
{record["repo_id"] for record in response.data}
if response.data
else set()
)

# 筛选出未存在的记录
new_records_data = [
data
for data in records_data
if data["repo_id"] not in existing_repo_ids
]

if not new_records_data:
return False, {
"message": "No new GithubRepoConfig records to insert, all repo_ids already exist"
}
else:
return False, {"message": "GithubRepoConfig batch creation failed"}

# 执行插入操作
repo_config_result = (
self.client.table("github_repo_config")
.insert(new_records_data)
.execute()
)

return repo_config_result
except Exception as e:
print(f"Error: {e}")
return False, {"message": f"GithubRepoConfig batch creation failed: {e}"}
Expand Down

0 comments on commit 22e06a2

Please sign in to comment.