pg_cache_key 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6de9641f70be650b00f1aea66b0b19c4b805183b
4
- data.tar.gz: b3d53d547d4bcc550bebb5f9b5575c06498b2e6a
3
+ metadata.gz: e77a9f091922442dc6b19d2015d53e1e7bf93ece
4
+ data.tar.gz: 339813b6a21d0b8de74412de8b62567ad341ab3e
5
5
  SHA512:
6
- metadata.gz: ab9e30ce53ffe894d2ece3af511d0e947b65055582814440f64649ded86e41c4769bcb9aa361fec35dec7660460c58babc4d86a7b39dd0fe0903cc08a00c2030
7
- data.tar.gz: d0ff6f9564c326282ec1d884fd84d7f1583318f53c8fbf0dd9838a49fb00d0ecdae2794f5541fa4ab923493db32743b8e1cc688e7b44ee297f9bb9b3fc9b03f8
6
+ metadata.gz: 930b14dc2c3545747b6209db0f378d403eb3a695b04de241ac6e934d5483636db09c6fb8bb109986bc918dd9c0782d8adc3a0e063848c63184662b5e93a4e448
7
+ data.tar.gz: 20bf20ebcda951fae3d0e5107bbd08de7e2a10c7be761daccbdf2f12c9ddaeeba91ecb16177bd2980658da9c60e6697a1358fe35842e19a6b65f7ba844535410
data/README.md CHANGED
@@ -71,11 +71,12 @@ It works out of the box.
71
71
 
72
72
  По идее работает само из коробки, но если будут траблы - пишите.
73
73
 
74
- ## Development
74
+ ## Testing
75
+ Tested only query string for simple case. In your project you may test it on more specific query.
75
76
 
76
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
77
-
78
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
77
+ ## Testing(рус)
78
+ Тестируется только строка запроса для самого простого случая + добавление метода в активрекорд релейшен.
79
+ Стабильность на сложных запросах специфических для вашего приложения можете добавить в свои тесты.
79
80
 
80
81
  ## Contributing
81
82
 
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'rspec/core/rake_task'
2
2
  task :default => :spec
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+
@@ -1,3 +1,3 @@
1
1
  module PgCacheKey
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/pg_cache_key.rb CHANGED
@@ -15,18 +15,39 @@ require "pg_cache_key/version"
15
15
  # end
16
16
  # end
17
17
 
18
- # in rails >= 4 it would go like this:
18
+ module PgCacheKey
19
+ def cache_key_raw_sql( timestamp_column = :updated_at )
20
+ "SELECT md5(string_agg( t.ckc_#{timestamp_column}||t.ckc_id, '') ) as cache_key \
21
+ FROM (#{ select( [timestamp_column, :id].map{|ckc| "#{table_name}.#{ckc}::text as ckc_#{ckc}" } ).try(:to_sql) }) t"
22
+ end
23
+ end
24
+
25
+ # Actually this all depends on retrieve_cache_key(key) from active_support:
26
+ # def retrieve_cache_key(key)
27
+ # case
28
+ # when key.respond_to?(:cache_key) then key.cache_key
29
+ # when key.is_a?(Array) then key.map { |element| retrieve_cache_key(element) }.to_param
30
+ # when key.respond_to?(:to_a) then retrieve_cache_key(key.to_a)
31
+ # else key.to_param
32
+ # end.to_s
33
+ # end
34
+ # in rails 4 there is no cache_key in relations so if we deliver relation as key in rails 4 it will convert to array first
35
+ # in rails 5 there is cache_key, the method below is copy+paste from rails 5 except it doesn't use rails 5 collection_cache_key,
36
+ # and use it's own algorithm for cache_key
19
37
  module ActiveRecord
20
38
  # = Active Record \Relation
21
39
  class Relation
40
+ include PgCacheKey
41
+
22
42
  def cache_key(timestamp_column = :updated_at)
23
43
  @cache_keys ||= {}
24
44
  # Rem 1: why use connection.execute instead of doing collection.select because of an order. if you using some order on your scope
25
45
  # then columns you using to order must appear in the GROUP BY clause or be used in an aggregate function or you will get an error
26
46
  # Rem 2: we need to add select( cache_columns ) explicitly because if relation has includes it might transform columns to aliases
27
- @cache_keys[timestamp_column] ||= connection.execute(
28
- "SELECT md5(string_agg( t.cc_#{timestamp_column}||t.cc_id, '') ) as cache_key
29
- FROM (#{ select( [timestamp_column, :id].map{|cc| "#{table_name}.#{cc}::text as cc_#{cc}" } ).try(:to_sql) }) t" )[0]['cache_key']
47
+ # and we must also select them as uniq-aliase so PG wouldn't be confused
48
+ # 'ckc' means cache key column :)
49
+ @cache_keys[timestamp_column] ||= connection.execute( cache_key_raw_sql(timestamp_column) )[0]['cache_key']
30
50
  end
51
+
31
52
  end
32
53
  end
data/pg_cache_key.gemspec CHANGED
@@ -35,4 +35,6 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_development_dependency "bundler", "~> 1.13"
37
37
  spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec"
39
+ spec.add_development_dependency "sqlite3"
38
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_cache_key
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
  - alekseyl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-24 00:00:00.000000000 Z
11
+ date: 2016-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  description: 'collection_cache_key replacement for system which uses PG as DB, uses
70
98
  PG aggregation functions '
71
99
  email: