Skip to content

Commit

Permalink
[IMP] stock_average_daily_sale: avoid concurrent update
Browse files Browse the repository at this point in the history
  • Loading branch information
lmignon committed Nov 21, 2023
1 parent 90c0aff commit 3f33905
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions stock_average_daily_sale/models/stock_average_daily_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ def _check_view(self):
try:
cr = registry(self._cr.dbname).cursor()
new_self = self.with_env(self.env(cr=cr)) # TDE FIXME
new_self.env.cr.execute("SELECT COUNT(1) FROM %s", (AsIs(self._table),))
return True
new_self.env.cr.execute(
"SELECT ispopulated FROM pg_matviews WHERE matviewname = %s;",
(self._table,),
)
records = new_self.env.cr.fetchone()
return records and records[0]
except ObjectNotInPrerequisiteState:
_logger.warning(
_("The materialized view has not been populated. Launch the cron.")
Expand Down Expand Up @@ -141,7 +145,9 @@ def set_refresh_date(self, date=None):

@api.model
def refresh_view(self):
self.env.cr.execute("refresh materialized view %s", (AsIs(self._table),))
self.env.cr.execute(
"refresh materialized view CONCURRENTLY %s", (AsIs(self._table),)
)
self.set_refresh_date()

def _create_materialized_view(self):
Expand Down

0 comments on commit 3f33905

Please sign in to comment.