MCPcopy Index your code
hub / github.com/simstudioai/sim / incrementStorageUsage

Function incrementStorageUsage

apps/sim/lib/billing/storage/tracking.ts:71–114  ·  view source on GitHub ↗
(
  userId: string,
  bytes: number,
  workspaceId?: string
)

Source from the content-addressed store, hash-verified

69 * (80% / 100%) after the increment. Best-effort; never blocks the upload.
70 */
71export async function incrementStorageUsage(
72 userId: string,
73 bytes: number,
74 workspaceId?: string
75): Promise<void> {
76 if (!isBillingEnabled) {
77 logger.debug('Billing disabled, skipping storage increment')
78 return
79 }
80
81 let sub: HighestPrioritySubscription | null = null
82 try {
83 const { getHighestPrioritySubscription } = await import('@/lib/billing/core/subscription')
84 sub = await getHighestPrioritySubscription(userId)
85
86 // Org-scoped subs pool at the org level; personal plans per-user.
87 if (isOrgScopedSubscription(sub, userId) && sub) {
88 await db
89 .update(organization)
90 .set({
91 storageUsedBytes: sql`${organization.storageUsedBytes} + ${bytes}`,
92 })
93 .where(eq(organization.id, sub.referenceId))
94
95 logger.info(`Incremented org storage: ${bytes} bytes for org ${sub.referenceId}`)
96 } else {
97 await db
98 .update(userStats)
99 .set({
100 storageUsedBytes: sql`${userStats.storageUsedBytes} + ${bytes}`,
101 })
102 .where(eq(userStats.userId, userId))
103
104 logger.info(`Incremented user storage: ${bytes} bytes for user ${userId}`)
105 }
106 } catch (error) {
107 logger.error('Error incrementing storage usage:', error)
108 throw error
109 }
110
111 if (workspaceId) {
112 void maybeNotifyStorageLimit(userId, workspaceId, sub)
113 }
114}
115
116/**
117 * Decrement storage usage after file deletion

Callers 3

uploadWorkspaceFileFunction · 0.90

Calls 8

isOrgScopedSubscriptionFunction · 0.90
maybeNotifyStorageLimitFunction · 0.85
debugMethod · 0.80
infoMethod · 0.80
errorMethod · 0.80
setMethod · 0.65
eqFunction · 0.50

Tested by

no test coverage detected