This commit is contained in:
Timothy Jaeryang Baek
2026-02-21 15:35:34 -06:00
parent c114fd6876
commit 631e30e22d
26 changed files with 177 additions and 164 deletions
+1 -3
View File
@@ -439,9 +439,7 @@ class ChannelTable:
"channel", channel_ids, db=db
)
return [
self._to_channel_model(
c, access_grants=grants_map.get(c.id, []), db=db
)
self._to_channel_model(c, access_grants=grants_map.get(c.id, []), db=db)
for c in all_channels
]
+11 -29
View File
@@ -984,9 +984,7 @@ class ChatTable:
try:
with get_db_context(db) as db:
return db.query(
exists().where(
and_(Chat.id == id, Chat.user_id == user_id)
)
exists().where(and_(Chat.id == id, Chat.user_id == user_id))
).scalar()
except Exception:
return False
@@ -1001,9 +999,7 @@ class ChatTable:
try:
with get_db_context(db) as db:
result = (
db.query(Chat.folder_id)
.filter_by(id=id, user_id=user_id)
.first()
db.query(Chat.folder_id).filter_by(id=id, user_id=user_id).first()
)
return result[0] if result else None
except Exception:
@@ -1074,9 +1070,7 @@ class ChatTable:
db.query(Chat)
.filter_by(user_id=user_id, pinned=True, archived=False)
.order_by(Chat.updated_at.desc())
.with_entities(
Chat.id, Chat.title, Chat.updated_at, Chat.created_at
)
.with_entities(Chat.id, Chat.title, Chat.updated_at, Chat.created_at)
)
return [
ChatTitleIdResponse.model_validate(
@@ -1214,29 +1208,23 @@ class ChatTable:
# Check if there are any tags to filter, it should have all the tags
if "none" in tag_ids:
query = query.filter(
text(
"""
query = query.filter(text("""
NOT EXISTS (
SELECT 1
FROM json_each(Chat.meta, '$.tags') AS tag
)
"""
)
)
"""))
elif tag_ids:
query = query.filter(
and_(
*[
text(
f"""
text(f"""
EXISTS (
SELECT 1
FROM json_each(Chat.meta, '$.tags') AS tag
WHERE tag.value = :tag_id_{tag_idx}
)
"""
).params(**{f"tag_id_{tag_idx}": tag_id})
""").params(**{f"tag_id_{tag_idx}": tag_id})
for tag_idx, tag_id in enumerate(tag_ids)
]
)
@@ -1272,29 +1260,23 @@ class ChatTable:
# Check if there are any tags to filter, it should have all the tags
if "none" in tag_ids:
query = query.filter(
text(
"""
query = query.filter(text("""
NOT EXISTS (
SELECT 1
FROM json_array_elements_text(Chat.meta->'tags') AS tag
)
"""
)
)
"""))
elif tag_ids:
query = query.filter(
and_(
*[
text(
f"""
text(f"""
EXISTS (
SELECT 1
FROM json_array_elements_text(Chat.meta->'tags') AS tag
WHERE tag = :tag_id_{tag_idx}
)
"""
).params(**{f"tag_id_{tag_idx}": tag_id})
""").params(**{f"tag_id_{tag_idx}": tag_id})
for tag_idx, tag_id in enumerate(tag_ids)
]
)
+1 -3
View File
@@ -286,9 +286,7 @@ class KnowledgeTable:
{
**self._to_knowledge_model(
knowledge_base,
access_grants=grants_map.get(
knowledge_base.id, []
),
access_grants=grants_map.get(knowledge_base.id, []),
db=db,
).model_dump(),
"user": (
+1 -3
View File
@@ -230,9 +230,7 @@ class ModelsTable:
def get_base_models(self, db: Optional[Session] = None) -> list[ModelModel]:
with get_db_context(db) as db:
all_models = (
db.query(Model).filter(Model.base_model_id == None).all()
)
all_models = db.query(Model).filter(Model.base_model_id == None).all()
model_ids = [model.id for model in all_models]
grants_map = AccessGrants.get_grants_by_resources("model", model_ids, db=db)
return [
+6 -2
View File
@@ -217,7 +217,9 @@ class PromptsTable:
users = Users.get_users_by_user_ids(user_ids, db=db) if user_ids else []
users_dict = {user.id: user for user in users}
grants_map = AccessGrants.get_grants_by_resources("prompt", prompt_ids, db=db)
grants_map = AccessGrants.get_grants_by_resources(
"prompt", prompt_ids, db=db
)
prompts = []
for prompt in all_prompts:
@@ -343,7 +345,9 @@ class PromptsTable:
items = query.all()
prompt_ids = [prompt.id for prompt, _ in items]
grants_map = AccessGrants.get_grants_by_resources("prompt", prompt_ids, db=db)
grants_map = AccessGrants.get_grants_by_resources(
"prompt", prompt_ids, db=db
)
prompts = []
for prompt, user in items:
+3 -1
View File
@@ -283,7 +283,9 @@ class SkillsTable:
items = query.all()
skill_ids = [skill.id for skill, _ in items]
grants_map = AccessGrants.get_grants_by_resources("skill", skill_ids, db=db)
grants_map = AccessGrants.get_grants_by_resources(
"skill", skill_ids, db=db
)
skills = []
for skill, user in items: