dbhero 1.1.9 → 1.1.10

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: e47e5d70e515174e5d2c4db8270096351ae849f9
4
- data.tar.gz: 294c508e7756984944fbe565fa6a85c427cf3d72
3
+ metadata.gz: 704f1ecef47798c3d2f6e0f1bedf4fc33f836c0a
4
+ data.tar.gz: f2ba345d1695e024d9b7347a1d9ba2828cf22687
5
5
  SHA512:
6
- metadata.gz: ed2a0c67445990ccb954a5ddd2e4c934d46fcc5b92118391337743fafda69349aa59a512df30192462f722ecbcbccd0a3660a9200100587cf830edf1a6edccef
7
- data.tar.gz: 559ed3e990a8df329353d4c22493903f98d33f198e20f2550cf19b1787cb7ec14d75e38acfafc96d81057e159f3de178f1d3e5ea25b004a419be8140e571eba1
6
+ metadata.gz: b93cfb176d3c44c692cf5131af3cf3b0dfebb1530da36695bb9ca8b3b7b64792e6832a6fb597674fa007b1a2e7ee8b11d66bee6b6163c208dd1a8c19a0447c7e
7
+ data.tar.gz: c0b0217ae72a12906543ee967435ec770fa60fcd0f7fab585e3347fe063e08601104615713d21164356c8436befde8c3f2cebabfc9124104e9c9d97c329e7af4
@@ -3,6 +3,7 @@ require 'csv'
3
3
  module Dbhero
4
4
  class Dataclip < ActiveRecord::Base
5
5
  before_create :set_token
6
+ after_save :refresh_cache
6
7
 
7
8
  scope :ordered, -> { order(updated_at: :desc) }
8
9
  scope :search, ->(term) { where(arel_table[:description].matches("%#{term}%")) }
@@ -10,6 +11,11 @@ module Dbhero
10
11
  validates :description, :raw_query, presence: true
11
12
  attr_reader :q_result
12
13
 
14
+ def refresh_cache
15
+ Rails.cache.delete("dataclip_#{self.token}")
16
+ end
17
+
18
+
13
19
  def set_token
14
20
  self.token = SecureRandom.uuid unless self.token
15
21
  end
@@ -30,10 +36,16 @@ module Dbhero
30
36
  @total_rows ||= @q_result.rows.length
31
37
  end
32
38
 
39
+ def cached?
40
+ @cached ||= Rails.cache.fetch("dataclip_#{self.token}").present?
41
+ end
42
+
33
43
  def query_result
34
- Dataclip.transaction do
44
+ DataclipRead.transaction do
35
45
  begin
36
- @q_result ||= ActiveRecord::Base.connection.select_all(self.raw_query)
46
+ @q_result ||= Rails.cache.fetch("dataclip_#{self.token}") do
47
+ DataclipRead.connection.select_all(self.raw_query)
48
+ end
37
49
  rescue => e
38
50
  self.errors.add(:base, e.message)
39
51
  end
@@ -0,0 +1,6 @@
1
+ class Dbhero::DataclipRead < Dbhero::Dataclip
2
+ if ENV['READ_REPLICA_DB_URL'].present?
3
+ self.abstract_class = true
4
+ establish_connection(ENV['READ_REPLICA_DB_URL'])
5
+ end
6
+ end
@@ -17,7 +17,7 @@
17
17
  .input-field
18
18
  = f.text_area :raw_query, class: 'editor-style z-depth-1'
19
19
  .row
20
- .col.s5
20
+ .col.s9
21
21
  .input-field
22
22
  .switch
23
23
  label
@@ -25,8 +25,8 @@
25
25
  = f.check_box :private
26
26
  span.lever style='float: left;'
27
27
  i style="margin-top: -20px; float: left" class="small mdi-action-lock-outline tooltipped" data-position="right" data-delay="50" data-tooltip="Only users that same role as you can see the clip"
28
- .col.s7.right-align
28
+ .col.s3.right-align
29
29
  .input-field
30
30
  button class="btn waves-effect waves-light blue darken-3" type="submit" name="action"
31
- | Save
31
+ | Save & Refresh
32
32
  i class="mdi-action-done-all left"
@@ -1,3 +1,3 @@
1
1
  module Dbhero
2
- VERSION = "1.1.9"
2
+ VERSION = "1.1.10"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbhero
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.9
4
+ version: 1.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antônio Roberto Silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-09 00:00:00.000000000 Z
11
+ date: 2016-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -181,6 +181,7 @@ files:
181
181
  - app/helpers/dbhero/application_helper.rb
182
182
  - app/helpers/dbhero/dataclips_helper.rb
183
183
  - app/models/dbhero/dataclip.rb
184
+ - app/models/dbhero/dataclip_read.rb
184
185
  - app/views/dbhero/dataclips/_clip_table.html.slim
185
186
  - app/views/dbhero/dataclips/_form.html.slim
186
187
  - app/views/dbhero/dataclips/edit.html.slim