fix: exclude admin/system users from all third-party API tasks

Catalog, VK catalog, and VK sync tasks were querying all connections
regardless of user role. Admin and system accounts with stored tokens
were generating unnecessary Evotor and VK API calls. Now all three
tasks join to the users table and filter role = 'user' only.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
mguschin
2026-05-24 16:14:26 +03:00
parent e0594f67a8
commit 9f87458e0c
3 changed files with 9 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ from web.config import settings
from web.database import SessionLocal
import web.lib.api_logger as api_logger
from web.models.connections import CachedGroup, CachedProduct, CachedStore, EvotorConnection, SyncConfig, SyncFilter
from web.models.user import User, UserRoleEnum
logger = logging.getLogger(__name__)
@@ -207,10 +208,12 @@ def refresh_catalog(self) -> dict:
try:
connections = (
db.query(EvotorConnection)
.join(User, User.id == EvotorConnection.user_id)
.filter(
EvotorConnection.user_id.isnot(None),
EvotorConnection.access_token.isnot(None),
EvotorConnection.access_token != "",
User.role == UserRoleEnum.user,
)
.all()
)

View File

@@ -11,6 +11,7 @@ import web.lib.api_logger as api_logger
from web.config import settings
from web.database import SessionLocal
from web.models.connections import SyncConfig, VkCachedAlbum, VkCachedProduct, VkConnection
from web.models.user import User, UserRoleEnum
logger = logging.getLogger(__name__)
@@ -162,12 +163,14 @@ def refresh_vk_catalog(self) -> dict:
try:
connections = (
db.query(VkConnection)
.join(User, User.id == VkConnection.user_id)
.filter(
VkConnection.user_id.isnot(None),
VkConnection.access_token.isnot(None),
VkConnection.access_token != "",
VkConnection.vk_user_id.isnot(None),
VkConnection.vk_user_id != "",
User.role == UserRoleEnum.user,
)
.all()
)

View File

@@ -20,6 +20,7 @@ from web.models.connections import (
SyncConfig, SyncFilter,
VkCachedAlbum, VkConnection,
)
from web.models.user import User, UserRoleEnum
logger = logging.getLogger(__name__)
@@ -412,12 +413,14 @@ def mirror_to_vk(self) -> dict:
try:
vk_connections = (
db.query(VkConnection)
.join(User, User.id == VkConnection.user_id)
.filter(
VkConnection.user_id.isnot(None),
VkConnection.access_token.isnot(None),
VkConnection.access_token != "",
VkConnection.vk_user_id.isnot(None),
VkConnection.vk_user_id != "",
User.role == UserRoleEnum.user,
)
.all()
)