Feat: Implement usage limits for free tier users #252
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Short Summary
This PR introduces a comprehensive usage limitation system for the Free tier to ensure sustainable resource allocation and incentivize Premium upgrades. It implements limits on file storage (50MB), the number of active canvases (max 5), and restricts access to specific premium nodes (GitHub). This includes full-stack implementation from database schema changes and atomic storage reservation logic to frontend state management and UI enforcement.
Technical Changes
Backend (API & Database)
api/app/database/pg/models.py,api/migrations):UserStorageUsagetable to track total bytes used per user.c8c2d84a3b86for the new table.api/app/database/pg/user_ops/storage_crud.py):check_and_reserve_storage: Atomically checks limits and updates usage with row locking to prevent race conditions during concurrent uploads.release_storage: Decrements usage upon file deletion.get_recursive_item_size: Calculates the size of folders/files for accurate quota management.Filestable size withUserStorageUsageif records drift or are missing.api/app/database/pg/user_ops/usage_limits.py):check_free_tier_canvas_limit: Enforces a hard limit of 5 non-temporary graphs for free users.validate_premium_nodes: Blocks creation/update of graphs containing premium-only nodes (e.g., GitHub nodes) for free users.get_user_query_usageto return storage metrics (used vs limited bytes).Frontend (Nuxt/Vue)
ui/app/stores/usageStore.ts):usageStoreto trackstorageUsage(used bytes, limit, percentage).useFormatters.tsto use binary prefixes (1024) for accurate matching with backend file system logic.PLAN_LIMITSconstant for centralized limit definitions.Impact and Scope
user_storage_usage).GET /users/usageresponse signature changed to include storage data.with_for_update) is used during file uploads to ensure quota integrity.