From e4ef927da31eae612a28b914207b92e1bbdbc359 Mon Sep 17 00:00:00 2001 From: Murtuza Zabuawala Date: Thu, 23 Jun 2016 13:06:05 +0100 Subject: [PATCH] Fix tablespace statistics. Fixes #1196 --- .../server_groups/servers/tablespaces/__init__.py | 11 +++++------ .../templates/tablespaces/js/tablespaces.js | 4 +++- .../templates/tablespaces/sql/9.1_plus/stats.sql | 7 +++++-- .../templates/tablespaces/sql/9.2_plus/stats.sql | 7 +++++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py b/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py index c2cebd95a..b853defab 100644 --- a/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/tablespaces/__init__.py @@ -558,16 +558,15 @@ class TablespaceView(PGChildNodeView): "/".join([self.template_path, 'stats.sql']), tsid=tsid, conn=self.conn ) - status, res = self.conn.execute_scalar(SQL) + status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) - # TODO:// Format & return output of stats call accordingly - # TODO:// for now it's hardcoded as below - result = 'Tablespace Size: {0}'.format(res) - - return ajax_response(response=result) + return make_json_response( + data=res, + status=200 + ) @check_precondition def dependencies(self, gid, sid, tsid): diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/js/tablespaces.js b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/js/tablespaces.js index fc2b2d065..601372ee7 100644 --- a/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/js/tablespaces.js +++ b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/js/tablespaces.js @@ -8,7 +8,8 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { node: 'tablespace', label: '{{ _('Tablespaces') }}', type: 'coll-tablespace', - columns: ['name', 'spcuser', 'description'] + columns: ['name', 'spcuser', 'description'], + hasStatistics: true }); }; @@ -23,6 +24,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { hasSQL: true, canDrop: true, hasDepends: true, + hasStatistics: true, Init: function() { /* Avoid mulitple registration of menus */ if (this.initialized) diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.1_plus/stats.sql b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.1_plus/stats.sql index 02a1199b1..3f91b023c 100644 --- a/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.1_plus/stats.sql +++ b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.1_plus/stats.sql @@ -1,6 +1,9 @@ {### SQL to fetch tablespace object stats ###} {% if tsid %} -SELECT pg_size_pretty(pg_tablespace_size({{ tsid|qtLiteral }}::OID)) AS size +SELECT pg_size_pretty(pg_tablespace_size({{ tsid|qtLiteral }}::OID)) AS {{ conn|qtIdent(_('Size')) }} {% else %} -SELECT ts.spcname as name, pg_size_pretty(pg_tablespace_size(ts.oid)) AS size FROM pg_catalog.pg_tablespace ts; +SELECT ts.spcname AS {{ conn|qtIdent(_('Name')) }}, + pg_size_pretty(pg_tablespace_size(ts.oid)) AS {{ conn|qtIdent(_('Size')) }} +FROM + pg_catalog.pg_tablespace ts; {% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.2_plus/stats.sql b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.2_plus/stats.sql index 0abfd3735..3f91b023c 100644 --- a/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.2_plus/stats.sql +++ b/web/pgadmin/browser/server_groups/servers/tablespaces/templates/tablespaces/sql/9.2_plus/stats.sql @@ -1,6 +1,9 @@ {### SQL to fetch tablespace object stats ###} {% if tsid %} -SELECT pg_size_pretty(pg_tablespace_size({{ qtLiteral(tsid) }}::OID)) AS size +SELECT pg_size_pretty(pg_tablespace_size({{ tsid|qtLiteral }}::OID)) AS {{ conn|qtIdent(_('Size')) }} {% else %} -SELECT ts.spcname as name, pg_size_pretty(pg_tablespace_size(ts.oid)) AS size FROM pg_catalog.pg_tablespace ts; +SELECT ts.spcname AS {{ conn|qtIdent(_('Name')) }}, + pg_size_pretty(pg_tablespace_size(ts.oid)) AS {{ conn|qtIdent(_('Size')) }} +FROM + pg_catalog.pg_tablespace ts; {% endif %}