Skip to content
Permalink
Browse files
[DbManager] allow to refresh materialized views
(fixes #13697)
  • Loading branch information
SebDieBln authored and m-kuhn committed May 13, 2016
1 parent 1013458 commit c5308754ebb2cd7eb4e9ae344cd00e9f1e0dfd89
@@ -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)
@@ -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:
@@ -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):

@@ -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)

@@ -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):

0 comments on commit c530875

Please sign in to comment.