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:
@@ -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()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user