Skip to content

Commit

Permalink
[DbManager] allow to refresh materialized views
Browse files Browse the repository at this point in the history
(fixes #13697)
  • Loading branch information
SebDieBln authored and m-kuhn committed May 13, 2016
1 parent 1013458 commit c530875
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/plugins/db_manager/db_plugins/postgis/connector.py
Expand Up @@ -831,6 +831,12 @@ def runVacuumAnalyze(self, table):
self._execute(None, sql)
self._commit()

def runRefreshMaterializedView(self, table):
""" run refresh materialized view on a table """
sql = u"REFRESH MATERIALIZED VIEW %s" % self.quoteId(table)
self._execute(None, sql)
self._commit()

def addTableColumn(self, table, field_def):
""" add a column to table """
sql = u"ALTER TABLE %s ADD %s" % (self.quoteId(table), field_def)
Expand Down
26 changes: 26 additions & 0 deletions python/plugins/db_manager/db_plugins/postgis/plugin.py
Expand Up @@ -134,6 +134,9 @@ def registerDatabaseActions(self, mainWindow):
action = QAction(self.tr("Run &Vacuum Analyze"), self)
mainWindow.registerAction(action, self.tr("&Table"), self.runVacuumAnalyzeActionSlot)

action = QAction(self.tr("Run &Refresh Materialized View"), self)
mainWindow.registerAction(action, self.tr("&Table"), self.runRefreshMaterializedViewSlot)

def runVacuumAnalyzeActionSlot(self, item, action, parent):
QApplication.restoreOverrideCursor()
try:
Expand All @@ -146,6 +149,18 @@ def runVacuumAnalyzeActionSlot(self, item, action, parent):

item.runVacuumAnalyze()

def runRefreshMaterializedViewSlot(self, item, action, parent):
QApplication.restoreOverrideCursor()
try:
if not isinstance(item, PGTable) or item._relationType != 'm':
parent.infoBar.pushMessage(self.tr("Select a materialized view for refresh."), QgsMessageBar.INFO,
parent.iface.messageTimeout())
return
finally:
QApplication.setOverrideCursor(Qt.WaitCursor)

item.runRefreshMaterializedView()


class PGSchema(Schema):

Expand All @@ -168,6 +183,12 @@ def runVacuumAnalyze(self):
# TODO: change only this item, not re-create all the tables in the schema/database
self.schema().refresh() if self.schema() else self.database().refresh()

def runRefreshMaterializedView(self):
self.aboutToChange()
self.database().connector.runRefreshMaterializedView((self.schemaName(), self.name))
# TODO: change only this item, not re-create all the tables in the schema/database
self.schema().refresh() if self.schema() else self.database().refresh()

def runAction(self, action):
action = unicode(action)

Expand Down Expand Up @@ -198,6 +219,11 @@ def runAction(self, action):
self.refreshRules()
return True

elif action.startswith("refreshmaterializedview/"):
if action == "refreshmaterializedview/run":
self.runRefreshMaterializedView()
return True

return Table.runAction(self, action)

def tableFieldsFactory(self, row, table):
Expand Down

0 comments on commit c530875

Please sign in to comment.