File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
npm-packages/system-udfs/convex/_system/frontend Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 1+ import sum from "lodash/sum" ;
12import { queryGeneric } from "../secretSystemTables" ;
23import { v } from "convex/values" ;
4+ import { DatabaseReader } from "../../_generated/server" ;
35
46export default queryGeneric ( {
57 args : { tableName : v . string ( ) } ,
@@ -11,3 +13,26 @@ export default queryGeneric({
1113 return await db . query ( tableName ) . count ( ) ;
1214 } ,
1315} ) ;
16+
17+ export const sizeOfAllTables = queryGeneric ( {
18+ args : { } ,
19+ handler : async function allTableSizes ( { db } ) : Promise < number > {
20+ // Getting private system table here is OK because there are no args to this
21+ // system UDF.
22+ const tables = await ( ( db as any ) . privateSystem as DatabaseReader )
23+ . query ( "_tables" )
24+ . filter ( ( q ) => q . eq ( q . field ( "state" ) , "active" ) )
25+ . collect ( ) ;
26+ const tablesWithoutSystemTables = tables
27+ . map ( ( table ) => table . name )
28+ . filter ( ( tableName ) => ! tableName . startsWith ( "_" ) ) ;
29+
30+ const tableCounts = Promise . all (
31+ tablesWithoutSystemTables . map ( async ( tableName ) => {
32+ return await db . query ( tableName as any ) . count ( ) ;
33+ } ) ,
34+ ) ;
35+
36+ return sum ( await tableCounts ) ;
37+ } ,
38+ } ) ;
You can’t perform that action at this time.
0 commit comments