This commit is contained in:
@@ -13,15 +13,15 @@ from sqlalchemy import (
|
||||
UniqueConstraint,
|
||||
distinct,
|
||||
func,
|
||||
text,
|
||||
)
|
||||
from sqlalchemy.ext.hybrid import hybrid_property
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from auth.orm import Author
|
||||
from orm.base import BaseModel
|
||||
from orm.shout import Shout
|
||||
from services.db import local_session
|
||||
from auth.rbac_interface import get_rbac_operations
|
||||
from rbac.interface import get_rbac_operations
|
||||
from storage.db import local_session
|
||||
|
||||
# Словарь названий ролей
|
||||
role_names = {
|
||||
@@ -355,7 +355,13 @@ class CommunityStats:
|
||||
|
||||
@property
|
||||
def shouts(self) -> int:
|
||||
return self.community.session.query(func.count(Shout.id)).filter(Shout.community == self.community.id).scalar()
|
||||
return (
|
||||
self.community.session.query(func.count(1))
|
||||
.select_from(text("shout"))
|
||||
.filter(text("shout.community_id = :community_id"))
|
||||
.params(community_id=self.community.id)
|
||||
.scalar()
|
||||
)
|
||||
|
||||
@property
|
||||
def followers(self) -> int:
|
||||
@@ -370,12 +376,10 @@ class CommunityStats:
|
||||
# author has a shout with community id and its featured_at is not null
|
||||
return (
|
||||
self.community.session.query(func.count(distinct(Author.id)))
|
||||
.join(Shout)
|
||||
.filter(
|
||||
Shout.community == self.community.id,
|
||||
Shout.featured_at.is_not(None),
|
||||
Author.id.in_(Shout.authors),
|
||||
)
|
||||
.select_from(text("author"))
|
||||
.join(text("shout"), text("author.id IN (SELECT author_id FROM shout_author WHERE shout_id = shout.id)"))
|
||||
.filter(text("shout.community_id = :community_id"), text("shout.featured_at IS NOT NULL"))
|
||||
.params(community_id=self.community.id)
|
||||
.scalar()
|
||||
)
|
||||
|
||||
@@ -498,7 +502,7 @@ class CommunityAuthor(BaseModel):
|
||||
# Используем fallback на проверку ролей
|
||||
return permission in self.role_list
|
||||
except Exception:
|
||||
# FIXME: Fallback: проверяем роли (старый способ)
|
||||
# TODO: Fallback: проверяем роли (старый способ)
|
||||
return any(permission == role for role in self.role_list)
|
||||
|
||||
def dict(self, access: bool = False) -> dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user