mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## Context Building on towards resource-aware Cmd K, the changes done up so far have all been to allow users to search for database resources from anywhere in the project, with the intention to get you to the resource quickly without having to go through the navigation hierarchy of the dashboard. This PR explores a way to quickly glance related resources for a table in the Table Editor through Cmd K for that same intention, but listing out the policies, triggers or functions that run on the table that you're currently viewing in the Table Editor. E.g here we've got the `blog_authors` table opened: <img width="500" alt="image" src="https://github.com/user-attachments/assets/78c9b85f-cd30-4564-a264-c1a2a596d5c2" /> Policies and triggers are fairly straight forward since we can determine what's related by their target table. Functions are a bit more fuzzy as we're trying to find what's related by checking the function definition, if it does anything to the table. For e.g based on the screenshot above, `blog_handle_new_user` has this definition which was why it was flagged <img width="500" alt="image" src="https://github.com/user-attachments/assets/fb8f3be4-05df-4d87-8440-8b75d95546ae" /> We're also deliberately decoupling loading of policies + triggers and functions since searching functions takes slightly longer, so opting to load results of policies + triggers first, then lazy load functions subsequently once results are ready ## Performance As usual, ran a benchmarking session with Claude just to make sure that the added SQL doesn't cause any performance issues, these are aggregates of 4–5 runs. **Catalog size (stress catalog)** | Query | 2,000 tables | 10,000 tables | |---|---|---| | Policies and triggers, hub table (many FKs) | 0.1 ms | 0.5–1.3 ms | | Policies and triggers, ordinary table | ~0 ms | ~0 ms | | Functions, every body matches | 1.4 ms | 4–8 ms | | Functions, no match (full scan) | 1.8 ms | 7.3–7.7 ms | | Functions, table not visible | 0 ms | 0 ms | **Large function bodies** (random text, 2,000 tables plus 2,000 small functions, plus the large ones added) | Function source | Largest function | Functions: no match (full scan) | Functions: every body matches | |---|---|---|---| | 56 MB (600 functions) | 94 KB | ~50 ms | 2 ms | | 103 MB (+10 multi-MB) | 4.7 MB | ~92 ms | 2 ms | ## To test Use a project with a table that has at least one policy, one trigger, and a function that mentions the table in its body. - [ ] Open that table in the Table Editor and press Cmd+K. A **Related resources** section appears at the top with its policies, triggers, and functions. - [ ] Click a policy, a trigger, and a function. Each opens its editor on the right resource. - [ ] A trigger's function does not also appear under the functions rows. - [ ] Type part of one of those names. The section narrows to matching rows and the project-wide entity results appear below. A resource can appear in both. - [ ] Type something that matches nothing in the table. The section disappears rather than showing empty. - [ ] Clear the input. The full section comes back without a loading flicker, since the data is cached. - [ ] Open the table editor on a table with no policies, triggers, or referencing functions. Cmd+K shows no empty **Related resources** section. - [ ] Switch to a different table and press Cmd+K. The section shows that table's resources, not the previous table's. - [ ] Open Cmd+K from a non-Table Editor page, such as the SQL Editor. The section is not shown. - [ ] In the network tab, check that opening the menu sends one query for policies and triggers and one for functions. Typing sends no additional ones for this section.
17 lines
438 B
TypeScript
17 lines
438 B
TypeScript
export const COMMAND_MENU_SECTIONS = {
|
|
ACTIONS: 'Actions',
|
|
RELATED_RESOURCES: 'Related resources',
|
|
NAVIGATE: 'Navigate',
|
|
QUERY: 'Queries',
|
|
SUPPORT: 'Support',
|
|
TABLE: 'Table Editor',
|
|
SQL: 'SQL Editor',
|
|
DATABASE: 'Database',
|
|
DATABASE_TABLES: 'Tables',
|
|
DATABASE_POLICIES: 'Policies',
|
|
DATABASE_TRIGGERS: 'Triggers',
|
|
DATABASE_FUNCTIONS: 'Functions',
|
|
INTEGRATIONS: 'Integrations',
|
|
SHORTCUTS: 'Shortcuts',
|
|
} as const
|