thegrumpys / odop

Open Design Optimization Platform (ODOP) - Coil spring design app; mechanical springs; compression spring, extension spring, torsion spring
https://www.springdesignsoftware.org
MIT License
4 stars 5 forks source link

Display DB Size on Help About modal #807

Closed 1fifoto closed 1 year ago

1fifoto commented 1 year ago

Display DB Size on Help About modal.

See #800.

1fifoto commented 1 year ago

Sample screen shot. Only displays in non-production environment (env !== 'production').

Screenshot 2023-01-20 at 2 32 27 PM

Internally the HelpAbout menu item transmits an /api/v1/db_size GET request to the ODOP server. The server receives the request and issues a SELECT query to the JAWS DB server for the size information (similar to what is done by the db_size.sh script). The DB server processes the SELECT, and returns the size and other things (see Note below) to the ODOP server. The ODOP server returns the size to the HelpAbout client.

This is the SELECT statement (edited from the db_size.sh script)

SELECT NOW() AS date_time, s.schema_name AS schema_name, sp.grantee AS user, CAST(ROUND(SUM(COALESCE(t.data_length + t.index_length, 0)) / 1024 / 1024, 3) AS CHAR) AS db_size_mb, sp.has_insert AS has_insert
FROM information_schema.schemata AS s
INNER JOIN information_schema.tables AS t
ON s.schema_name = t.table_schema
INNER JOIN (
    SELECT spi.grantee,spi.table_schema,MAX(
        CASE
            WHEN spi.privilege_type = 'INSERT' THEN 1
            ELSE 0
        END
    ) has_insert
    FROM information_schema.schema_privileges AS spi
    GROUP BY spi.grantee, spi.table_schema
) AS sp
ON s.schema_name = sp.table_schema
GROUP BY s.schema_name, sp.grantee, sp.has_insert

Note: Although the SELECT statement returns the date_time, schema_name, user, the db_size_mb and the has_insert, the ODOP server only returns the size to the HelpAbout menu client.

1fifoto commented 1 year ago

Merged into master, closing