fix: lazy load
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
"""tgex backend package."""
|
|
||||||
|
|||||||
@@ -135,7 +135,14 @@ class Postgres(DatabaseBase):
|
|||||||
async def add_external_channel_to_targets(
|
async def add_external_channel_to_targets(
|
||||||
self, external_channel_id: uuid.UUID, target_channel_ids: list[uuid.UUID]
|
self, external_channel_id: uuid.UUID, target_channel_ids: list[uuid.UUID]
|
||||||
) -> None:
|
) -> None:
|
||||||
external_channel = await self.session.get(domain.ExternalChannel, external_channel_id)
|
stmt = (
|
||||||
|
select(domain.ExternalChannel)
|
||||||
|
.where(domain.ExternalChannel.id == external_channel_id)
|
||||||
|
.options(selectinload(domain.ExternalChannel.target_channels))
|
||||||
|
)
|
||||||
|
result = await self.session.execute(stmt)
|
||||||
|
external_channel = result.scalar_one_or_none()
|
||||||
|
|
||||||
if not external_channel:
|
if not external_channel:
|
||||||
raise ValueError(f'ExternalChannel {external_channel_id} not found')
|
raise ValueError(f'ExternalChannel {external_channel_id} not found')
|
||||||
|
|
||||||
@@ -149,7 +156,14 @@ class Postgres(DatabaseBase):
|
|||||||
async def remove_external_channel_from_target(
|
async def remove_external_channel_from_target(
|
||||||
self, external_channel_id: uuid.UUID, target_channel_id: uuid.UUID
|
self, external_channel_id: uuid.UUID, target_channel_id: uuid.UUID
|
||||||
) -> None:
|
) -> None:
|
||||||
external_channel = await self.session.get(domain.ExternalChannel, external_channel_id)
|
stmt = (
|
||||||
|
select(domain.ExternalChannel)
|
||||||
|
.where(domain.ExternalChannel.id == external_channel_id)
|
||||||
|
.options(selectinload(domain.ExternalChannel.target_channels))
|
||||||
|
)
|
||||||
|
result = await self.session.execute(stmt)
|
||||||
|
external_channel = result.scalar_one_or_none()
|
||||||
|
|
||||||
if not external_channel:
|
if not external_channel:
|
||||||
raise ValueError(f'ExternalChannel {external_channel_id} not found')
|
raise ValueError(f'ExternalChannel {external_channel_id} not found')
|
||||||
|
|
||||||
|
|||||||
@@ -10,13 +10,12 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
async def disconnect_target_chan_by_tg_id(self: 'Usecase', input: dto.DisconnectTargetChanByTgIdInput) -> None:
|
async def disconnect_target_chan_by_tg_id(self: 'Usecase', input: dto.DisconnectTargetChanByTgIdInput) -> None:
|
||||||
# Получаем user_id по telegram_id
|
|
||||||
user = await self.database.get_user(telegram_id=input.user_telegram_id)
|
|
||||||
if not user:
|
|
||||||
log.warning(f'User with telegram_id {input.user_telegram_id} not found when disconnecting channel')
|
|
||||||
return
|
|
||||||
|
|
||||||
async with self.database.transaction():
|
async with self.database.transaction():
|
||||||
|
user = await self.database.get_user(telegram_id=input.user_telegram_id)
|
||||||
|
if not user:
|
||||||
|
log.warning(f'User with telegram_id {input.user_telegram_id} not found when disconnecting channel')
|
||||||
|
return
|
||||||
|
|
||||||
channel = await self.database.get_target_channel(user.id, telegram_id=input.telegram_id)
|
channel = await self.database.get_target_channel(user.id, telegram_id=input.telegram_id)
|
||||||
if not channel:
|
if not channel:
|
||||||
log.warning(f'Target channel {input.telegram_id} not found')
|
log.warning(f'Target channel {input.telegram_id} not found')
|
||||||
|
|||||||
Reference in New Issue
Block a user