mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 04:15:04 +03:00
The global storage size validation depends on an unpaginated buckets query to determine whether it is lower than any individual bucket's cutoff. This causes a problem for users with tens of thousands of buckets. There's a bit of a UX/performance problem here, because in order to determine whether any bucket's `file_size_limit` exceeds the global setting, we need to get the max `file_size_limit` of `storage.buckets` -- however, that column is not indexed. My workaround is: - Below a certain threshold (10,000) buckets, the query for max `file_size_limit` is automatically run on form submit. - Above that threshold, the user must confirm whether they want to run the query. They're still allowed to change the storage config without running it -- this does open a loophole where they can have a global storage setting lower than an individual bucket's file size limit, but though this is a potentially confusing situation, it's not strictly an error. --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
20 lines
549 B
TypeScript
20 lines
549 B
TypeScript
import { literal } from '@supabase/pg-meta/src/pg-format'
|
|
import { sqlKeys } from '../keys'
|
|
|
|
export const getLiveTupleEstimate = (table: string, schema: string = 'public') => {
|
|
const sql = /* SQL */ `
|
|
SELECT n_live_tup AS live_tuple_estimate
|
|
FROM pg_stat_user_tables
|
|
WHERE schemaname = ${literal(schema)}
|
|
AND relname = ${literal(table)};
|
|
`.trim()
|
|
|
|
return sql
|
|
}
|
|
|
|
export const getLiveTupleEstimateKey = (
|
|
projectRef: string | undefined,
|
|
table: string,
|
|
schema = 'public'
|
|
) => sqlKeys.query(projectRef, ['live-tuple-estimate', schema, table])
|