Skip to content

Commit 29b4d61

Browse files
committed
fix: Remove async from user_limits (Supabase client is sync)
- Changed all async def to def in user_limits.py - Removed await calls in routes/users.py - Matches codebase pattern (supabase_service.py uses sync)
1 parent a7c94ae commit 29b4d61

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

backend/routes/users.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
@router.get("/usage")
12-
async def get_user_usage(auth: AuthContext = Depends(require_auth)):
12+
def get_user_usage(auth: AuthContext = Depends(require_auth)):
1313
"""
1414
Get current user's usage and limits.
1515
@@ -42,14 +42,14 @@ async def get_user_usage(auth: AuthContext = Depends(require_auth)):
4242
}
4343
}
4444

45-
usage = await user_limits.get_usage_summary(user_id)
45+
usage = user_limits.get_usage_summary(user_id)
4646
logger.info("Usage retrieved", user_id=user_id, tier=usage.get("tier"))
4747

4848
return usage
4949

5050

5151
@router.get("/limits/check-repo-add")
52-
async def check_can_add_repo(auth: AuthContext = Depends(require_auth)):
52+
def check_can_add_repo(auth: AuthContext = Depends(require_auth)):
5353
"""
5454
Check if user can add another repository.
5555
@@ -61,5 +61,5 @@ async def check_can_add_repo(auth: AuthContext = Depends(require_auth)):
6161
if not user_id:
6262
return {"allowed": True, "message": "OK"}
6363

64-
result = await user_limits.check_repo_count(user_id)
64+
result = user_limits.check_repo_count(user_id)
6565
return result.to_dict()

backend/services/user_limits.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ class UserLimitsService:
106106
limits = UserLimitsService(supabase_client, redis_client)
107107
108108
# Check if user can add another repo
109-
result = await limits.check_repo_count(user_id)
109+
result = limits.check_repo_count(user_id)
110110
if not result.allowed:
111111
raise HTTPException(403, result.message)
112112
113113
# Check if repo size is within limits
114-
result = await limits.check_repo_size(user_id, file_count, function_count)
114+
result = limits.check_repo_size(user_id, file_count, function_count)
115115
if not result.allowed:
116116
raise HTTPException(400, result.message)
117117
"""
@@ -123,7 +123,7 @@ def __init__(self, supabase_client, redis_client=None):
123123

124124
# ===== TIER MANAGEMENT =====
125125

126-
async def get_user_tier(self, user_id: str) -> UserTier:
126+
def get_user_tier(self, user_id: str) -> UserTier:
127127
"""
128128
Get user's current tier.
129129
@@ -141,7 +141,7 @@ async def get_user_tier(self, user_id: str) -> UserTier:
141141
pass
142142

143143
# Query Supabase
144-
tier = await self._get_tier_from_db(user_id)
144+
tier = self._get_tier_from_db(user_id)
145145

146146
# Cache the result
147147
if self.redis:
@@ -150,7 +150,7 @@ async def get_user_tier(self, user_id: str) -> UserTier:
150150

151151
return tier
152152

153-
async def _get_tier_from_db(self, user_id: str) -> UserTier:
153+
def _get_tier_from_db(self, user_id: str) -> UserTier:
154154
"""Get tier from Supabase user_profiles table"""
155155
try:
156156
result = self.supabase.table("user_profiles").select("tier").eq("user_id", user_id).execute()
@@ -167,14 +167,14 @@ def get_limits(self, tier: UserTier) -> TierLimits:
167167
"""Get limits for a tier"""
168168
return TIER_LIMITS.get(tier, TIER_LIMITS[UserTier.FREE])
169169

170-
async def get_user_limits(self, user_id: str) -> TierLimits:
170+
def get_user_limits(self, user_id: str) -> TierLimits:
171171
"""Get limits for a specific user"""
172-
tier = await self.get_user_tier(user_id)
172+
tier = self.get_user_tier(user_id)
173173
return self.get_limits(tier)
174174

175175
# ===== REPO COUNT LIMITS (#95) =====
176176

177-
async def get_user_repo_count(self, user_id: str) -> int:
177+
def get_user_repo_count(self, user_id: str) -> int:
178178
"""Get current repo count for user"""
179179
try:
180180
result = self.supabase.table("repositories").select("id", count="exact").eq("user_id", user_id).execute()
@@ -183,16 +183,16 @@ async def get_user_repo_count(self, user_id: str) -> int:
183183
logger.error("Failed to get repo count", user_id=user_id, error=str(e))
184184
return 0
185185

186-
async def check_repo_count(self, user_id: str) -> LimitCheckResult:
186+
def check_repo_count(self, user_id: str) -> LimitCheckResult:
187187
"""
188188
Check if user can add another repository.
189189
190190
Returns:
191191
LimitCheckResult with allowed=True if under limit
192192
"""
193-
tier = await self.get_user_tier(user_id)
193+
tier = self.get_user_tier(user_id)
194194
limits = self.get_limits(tier)
195-
current_count = await self.get_user_repo_count(user_id)
195+
current_count = self.get_user_repo_count(user_id)
196196

197197
# Unlimited repos
198198
if limits.max_repos is None:
@@ -223,7 +223,7 @@ async def check_repo_count(self, user_id: str) -> LimitCheckResult:
223223

224224
# ===== REPO SIZE LIMITS (#94) =====
225225

226-
async def check_repo_size(
226+
def check_repo_size(
227227
self,
228228
user_id: str,
229229
file_count: int,
@@ -240,7 +240,7 @@ async def check_repo_size(
240240
Returns:
241241
LimitCheckResult with allowed=True if within limits
242242
"""
243-
tier = await self.get_user_tier(user_id)
243+
tier = self.get_user_tier(user_id)
244244
limits = self.get_limits(tier)
245245

246246
# Check file count
@@ -290,14 +290,14 @@ def get_playground_limit(self, tier: UserTier = UserTier.FREE) -> Optional[int]:
290290

291291
# ===== USAGE SUMMARY =====
292292

293-
async def get_usage_summary(self, user_id: str) -> Dict[str, Any]:
293+
def get_usage_summary(self, user_id: str) -> Dict[str, Any]:
294294
"""
295295
Get complete usage summary for user.
296296
Useful for dashboard display.
297297
"""
298-
tier = await self.get_user_tier(user_id)
298+
tier = self.get_user_tier(user_id)
299299
limits = self.get_limits(tier)
300-
repo_count = await self.get_user_repo_count(user_id)
300+
repo_count = self.get_user_repo_count(user_id)
301301

302302
return {
303303
"tier": tier.value,

0 commit comments

Comments
 (0)