ar-monocle 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e223d27b9b0fa7d4720eacd64a56937f256735a2
4
- data.tar.gz: 829fbc4d879893d7a8d014c3a00474d112aad446
3
+ metadata.gz: e4605eab43d5ef90c70e7c242c8e76a740cd77a0
4
+ data.tar.gz: 42cf6093efbda0ee8833413c481f512f99739dbf
5
5
  SHA512:
6
- metadata.gz: 1137ca323d94f3f472870bf5796171fd729c4ff915a9faec6bde18c0de80ff1e08632511dcb036b482b92ce525cc3a6c41bd8c57d2ad43a9b26c484fd424ecd1
7
- data.tar.gz: 07d3c8e4087d2167c633c49f1c5ade9c4c680ac4b8e220b0bb538786f9603b736d4e787d6de1d63cdcb1be7867f9df636cadc7dd1585fb7db64a3917a86637e7
6
+ metadata.gz: 9c5d66e5a7be45c7765d9b49389428da9f67cb6bfcd9b1d37986a22662321ff911715cff84fbfc937d549efba321c3dea457f3afb3a24280ed89de65d5cc8ed3
7
+ data.tar.gz: 1ad0d0d5d0c79bedbe5d8a477a0ef7dac5f9b34290cc4aba44e4418e1588ecc5c6305843bde1271c1eb147d41d6f3706e115d58d4fb892491008409b49c9a5f9
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ar-monocle (0.1.3)
4
+ ar-monocle (0.1.5)
5
5
  activerecord (>= 4, < 6)
6
6
  activesupport (>= 4, < 6)
7
7
  rake
data/README.md CHANGED
@@ -81,7 +81,17 @@ With monocle, you decide when it's time to upgrade a view. So even if you have a
81
81
 
82
82
  $ rake monocle:bump[my_view_name]
83
83
 
84
- It will automatically bump that view's timestamp to the current time.
84
+ ### Refresh a view
85
+
86
+ For materialized views, this makes it easy for you to trigger a refresh, say, in a cron job or something.
87
+
88
+ $ rake monocle:refresh[my_view_name]
89
+
90
+ ### Refresh all views
91
+
92
+ This is also available as a top level method for Monocle. It will refresh all your materialized views.
93
+
94
+ $ rake monocle:refresh_all
85
95
 
86
96
  ## Development
87
97
 
@@ -1,3 +1,3 @@
1
1
  module Monocle
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -69,8 +69,21 @@ module Monocle
69
69
  def refresh(concurrently: false)
70
70
  # We don't refresh normal views
71
71
  return false unless materialized?
72
- _concurrently = "CONCURRENTLY" if concurrently
73
- execute "REFRESH MATERIALIZED VIEW #{_concurrently} #{name}"
72
+ _concurrently = " CONCURRENTLY" if concurrently
73
+ execute "REFRESH MATERIALIZED VIEW#{_concurrently} #{name}"
74
+ true
75
+ rescue ActiveRecord::StatementInvalid => e
76
+ # This view is trying to select from a different view that hasn't been
77
+ # populated.
78
+ if e.message =~ /PG::ObjectNotInPrerequisiteState/ &&
79
+ e.message.scan(/materialized view \"(\w+)\" has not been populated/) &&
80
+ list.keys.include?($1.to_sym)
81
+ warn "Can't refresh #{name} because it depends on #{$1} which hasn't been populated, refreshing that first..."
82
+ list.fetch($1.to_sym).refresh
83
+ retry
84
+ else
85
+ fail e
86
+ end
74
87
  end
75
88
 
76
89
  def slug
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar-monocle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonardo Bighetti