File tree 1 file changed +25
-0
lines changed
npm-packages/system-udfs/convex/_system/frontend
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ import sum from "lodash/sum" ;
1
2
import { queryGeneric } from "../secretSystemTables" ;
2
3
import { v } from "convex/values" ;
4
+ import { DatabaseReader } from "../../_generated/server" ;
3
5
4
6
export default queryGeneric ( {
5
7
args : { tableName : v . string ( ) } ,
@@ -11,3 +13,26 @@ export default queryGeneric({
11
13
return await db . query ( tableName ) . count ( ) ;
12
14
} ,
13
15
} ) ;
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