# -*- coding: utf-8 -*- # @File: actions.py # @Date: 2025/10/15 18:58 # @Software: PyCharm # @Author: xingc # @Desc: import logging from sqlalchemy.ext.asyncio import AsyncSession from core.db.crud import CRUD from core.db.engine import async_db_session from core.db.models import User, UserFollows logger = logging.getLogger(__name__) async def update_user_follower_total( follower_id: int, followed_id: int, db_session: AsyncSession ): """ 更新用户计数 :param follower_id: 关注者id :param followed_id: 被关注者id :param db_session: :return: """ db_crud = CRUD(db_session, UserFollows) # 更新关注数 followers_count = await db_crud.total( filters={ 'follower_id': follower_id, 'followed_id': followed_id, } ) await db_crud.update( model=User, data={ 'followers_count': followers_count, }, filters={ 'user_id': follower_id, } ) # 更新粉丝数 fans_count = await db_crud.total( filters={ 'followed_id': followed_id, } ) await db_crud.update( model=User, data={ 'fans_count': fans_count, }, filters={ 'user_id': followed_id, } )