MCPcopy
hub / github.com/simstudioai/sim / getWorkspaceTableLimits

Function getWorkspaceTableLimits

apps/sim/lib/table/billing.ts:110–149  ·  view source on GitHub ↗
(workspaceId: string)

Source from the content-addressed store, hash-verified

108 * @returns Table limits based on the workspace's billing plan
109 */
110export async function getWorkspaceTableLimits(workspaceId: string): Promise<TablePlanLimits> {
111 const cached = limitsCache.get(workspaceId)
112 if (cached) {
113 if (cached.expiresAt > Date.now()) return cached.limits
114 limitsCache.delete(workspaceId)
115 }
116
117 const planLimits = getTablePlanLimits()
118
119 try {
120 const billedAccountUserId = await getWorkspaceBilledAccountUserId(workspaceId)
121
122 if (!billedAccountUserId) {
123 logger.warn('No billed account found for workspace, using free tier limits', { workspaceId })
124 cacheLimits(workspaceId, planLimits.free)
125 return planLimits.free
126 }
127
128 const subscription = await getHighestPrioritySubscription(billedAccountUserId)
129 const planName = getPlanTypeForLimits(subscription?.plan) as PlanName
130
131 const limits = planLimits[planName] ?? planLimits.free
132
133 logger.info('Retrieved workspace table limits', {
134 workspaceId,
135 billedAccountUserId,
136 planName,
137 limits,
138 })
139
140 cacheLimits(workspaceId, limits)
141 return limits
142 } catch (error) {
143 logger.error('Error getting workspace table limits, falling back to free tier', {
144 workspaceId,
145 error,
146 })
147 return planLimits.free
148 }
149}
150
151function cacheLimits(workspaceId: string, limits: TablePlanLimits): void {
152 // Keep the Map bounded for a new key: sweep expired entries, then (if a burst of

Callers 9

executeFunction · 0.90
billing.test.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
buildTableFunction · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
canCreateTableFunction · 0.85
getMaxRowsPerTableFunction · 0.85

Calls 10

getTablePlanLimitsFunction · 0.90
getPlanTypeForLimitsFunction · 0.90
cacheLimitsFunction · 0.85
infoMethod · 0.80
errorMethod · 0.80
getMethod · 0.65
deleteMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected