mongoid-collection-snapshot 1.3.1 → 1.3.2
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 +4 -4
- data/.rubocop_todo.yml +5 -5
- data/CHANGELOG.md +3 -2
- data/lib/mongoid-collection-snapshot.rb +12 -7
- data/lib/mongoid-collection-snapshot/version.rb +1 -1
- data/spec/config/mongoid3.yml +6 -0
- data/spec/config/mongoid4.yml +6 -0
- data/spec/config/mongoid5.yml +6 -0
- data/spec/config/mongoid6.yml +6 -0
- data/spec/mongoid/collection_snapshot_spec.rb +9 -0
- data/spec/mongoid/multiple_databases_spec.rb +63 -0
- data/spec/spec_helper.rb +1 -3
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 413b563ac9f33351ab543a7e72f56e7c5402802c
|
4
|
+
data.tar.gz: 803caae2c222ab14a8cbdcef6b1390a941cfed87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f27da72bb8c0308a12d0f79b7a06afd5c9317407036231bdda9995b9eec05f845641116d44fc28c042c758e2ce278c7cb31ed685d9ced8c5ea67e072f171ef9
|
7
|
+
data.tar.gz: f48f7d1e8414a9dbd7ba41f541d86b57382490ed7ea51a1aa2e93b4bb522f2d960ac9f22daea95ffb14c0965e1d577a94da20c1f258706cc88d04a3b5490ee7e
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2017-
|
3
|
+
# on 2017-06-03 12:33:20 -0400 using RuboCop version 0.47.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -26,18 +26,18 @@ Lint/UselessAccessModifier:
|
|
26
26
|
|
27
27
|
# Offense count: 3
|
28
28
|
Metrics/AbcSize:
|
29
|
-
Max:
|
29
|
+
Max: 37
|
30
30
|
|
31
31
|
# Offense count: 5
|
32
32
|
# Configuration parameters: CountComments, ExcludedMethods.
|
33
33
|
Metrics/BlockLength:
|
34
|
-
Max:
|
34
|
+
Max: 151
|
35
35
|
|
36
36
|
# Offense count: 1
|
37
37
|
Metrics/CyclomaticComplexity:
|
38
38
|
Max: 8
|
39
39
|
|
40
|
-
# Offense count:
|
40
|
+
# Offense count: 46
|
41
41
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
42
42
|
# URISchemes: http, https
|
43
43
|
Metrics/LineLength:
|
@@ -51,7 +51,7 @@ Metrics/MethodLength:
|
|
51
51
|
# Offense count: 1
|
52
52
|
# Configuration parameters: CountComments.
|
53
53
|
Metrics/ModuleLength:
|
54
|
-
Max:
|
54
|
+
Max: 153
|
55
55
|
|
56
56
|
# Offense count: 1
|
57
57
|
Metrics/PerceivedComplexity:
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
### 1.3.2 (
|
1
|
+
### 1.3.2 (6/4/2017)
|
2
2
|
|
3
|
-
*
|
3
|
+
* [#13](https://github.com/mongoid/mongoid-collection-snapshot/issues/13): Fix: use correct database on all threads - [@dblock](https://github.com/dblock).
|
4
|
+
* [#7](https://github.com/mongoid/mongoid-collection-snapshot/issues/7): Fix: `max_collection_snapshot_instances` broken - [@dblock](https://github.com/dblock).
|
4
5
|
|
5
6
|
### 1.3.1 (5/22/2017)
|
6
7
|
|
@@ -2,7 +2,7 @@ require 'mongoid-collection-snapshot/version'
|
|
2
2
|
|
3
3
|
module Mongoid
|
4
4
|
module CollectionSnapshot
|
5
|
-
extend ActiveSupport::Concern
|
5
|
+
extend ::ActiveSupport::Concern
|
6
6
|
|
7
7
|
DEFAULT_COLLECTION_KEY_NAME = '*'.freeze
|
8
8
|
|
@@ -16,10 +16,10 @@ module Mongoid
|
|
16
16
|
field :workspace_basename, default: 'snapshot'
|
17
17
|
slug :workspace_basename
|
18
18
|
|
19
|
-
|
19
|
+
class_attribute :max_collection_snapshot_instances
|
20
20
|
|
21
21
|
before_create :build
|
22
|
-
after_create :
|
22
|
+
after_create :ensure_at_most_max_instances_exist
|
23
23
|
before_destroy :drop_snapshot_collections
|
24
24
|
|
25
25
|
class_attribute :document_blocks
|
@@ -41,14 +41,18 @@ module Mongoid
|
|
41
41
|
cattr_accessor :mongo_session
|
42
42
|
end
|
43
43
|
instance_eval(&document_block) if document_block
|
44
|
-
store_in collection: collection_name
|
45
44
|
end
|
46
45
|
if Mongoid::Compatibility::Version.mongoid6?
|
47
|
-
|
48
|
-
|
46
|
+
# assign a name to the snapshot session
|
47
|
+
session_id = snapshot_session.object_id.to_s
|
48
|
+
Mongoid::Clients.set session_id, snapshot_session
|
49
|
+
# tell the class to use the client by name
|
50
|
+
klass.class_variable_set :@@storage_options, client: session_id, collection: collection_name
|
49
51
|
elsif Mongoid::Compatibility::Version.mongoid5?
|
52
|
+
klass.store_in collection: collection_name
|
50
53
|
klass.mongo_client = snapshot_session
|
51
54
|
else
|
55
|
+
klass.store_in collection: collection_name
|
52
56
|
klass.mongo_session = snapshot_session
|
53
57
|
end
|
54
58
|
Object.const_set(class_name, klass)
|
@@ -87,8 +91,9 @@ module Mongoid
|
|
87
91
|
# called after each save - making sure only at most two instances exists should be
|
88
92
|
# sufficient to ensure that this data can be rebuilt live without corrupting any
|
89
93
|
# existing computations that might have a handle to the previous "latest" instance.
|
90
|
-
def
|
94
|
+
def ensure_at_most_max_instances_exist
|
91
95
|
all_instances = self.class.order_by([[:created_at, :desc]]).to_a
|
96
|
+
max_collection_snapshot_instances = self.class.max_collection_snapshot_instances || 2
|
92
97
|
return unless all_instances.length > max_collection_snapshot_instances
|
93
98
|
all_instances[max_collection_snapshot_instances..-1].each(&:destroy)
|
94
99
|
end
|
@@ -55,6 +55,15 @@ module Mongoid
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
it 'maintains at most max_collection_snapshot_instances of the latest snapshots to support its calculations' do
|
59
|
+
AverageArtistPrice.max_collection_snapshot_instances = 5
|
60
|
+
AverageArtistPrice.create
|
61
|
+
10.times do
|
62
|
+
AverageArtistPrice.create
|
63
|
+
end
|
64
|
+
expect(AverageArtistPrice.count).to eq(5)
|
65
|
+
end
|
66
|
+
|
58
67
|
context '#documents' do
|
59
68
|
it 'provides access to a Mongoid collection' do
|
60
69
|
snapshot = AverageArtistPrice.create
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class Widget
|
4
|
+
include Mongoid::Document
|
5
|
+
end
|
6
|
+
|
7
|
+
class Gadget
|
8
|
+
include Mongoid::Document
|
9
|
+
end
|
10
|
+
|
11
|
+
class WidgetsAndGadgets
|
12
|
+
include Mongoid::CollectionSnapshot
|
13
|
+
|
14
|
+
document do
|
15
|
+
belongs_to :widget, inverse_of: nil
|
16
|
+
belongs_to :gadget, inverse_of: nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def build
|
20
|
+
collection_snapshot.drop
|
21
|
+
Widget.all.each do |widget|
|
22
|
+
Gadget.all.each do |gadget|
|
23
|
+
if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
|
24
|
+
collection_snapshot.insert_one(widget_id: widget.id, gadget_id: gadget.id)
|
25
|
+
else
|
26
|
+
collection_snapshot.insert(widget_id: widget.id, gadget_id: gadget.id)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def snapshot_session
|
33
|
+
if Mongoid::Compatibility::Version.mongoid5? || Mongoid::Compatibility::Version.mongoid6?
|
34
|
+
Mongoid.client('imports')
|
35
|
+
else
|
36
|
+
Mongoid.session('imports')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module Mongoid
|
42
|
+
describe CollectionSnapshot do
|
43
|
+
before do
|
44
|
+
Widget.delete_all
|
45
|
+
Gadget.delete_all
|
46
|
+
Widget.create!
|
47
|
+
Gadget.create!
|
48
|
+
WidgetsAndGadgets.each.map(&:collection_snapshot).each(&:drop)
|
49
|
+
WidgetsAndGadgets.create!
|
50
|
+
end
|
51
|
+
it 'uses the correct database on a separate thread' do
|
52
|
+
expect(WidgetsAndGadgets.latest.documents.count).to eq 1
|
53
|
+
require 'thread'
|
54
|
+
Thread.new do
|
55
|
+
expect(WidgetsAndGadgets.latest.documents.count).to eq 1
|
56
|
+
WidgetsAndGadgets.latest.documents.each do |pair|
|
57
|
+
expect(pair.widget).to_not be nil
|
58
|
+
expect(pair.gadget).to_not be nil
|
59
|
+
end
|
60
|
+
end.join
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,9 +5,7 @@ require 'rspec'
|
|
5
5
|
require 'mongoid'
|
6
6
|
require 'timecop'
|
7
7
|
|
8
|
-
Mongoid.
|
9
|
-
config.connect_to('mongoid-collection-snapshot_test')
|
10
|
-
end
|
8
|
+
Mongoid.load!("#{File.dirname(__FILE__)}/config/mongoid#{ENV['MONGOID_VERSION'] || 6}.yml", :test)
|
11
9
|
|
12
10
|
require File.expand_path('../../lib/mongoid-collection-snapshot', __FILE__)
|
13
11
|
Dir["#{File.dirname(__FILE__)}/models/**/*.rb"].each { |f| require f }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-collection-snapshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Windsor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
@@ -80,6 +80,10 @@ files:
|
|
80
80
|
- lib/mongoid-collection-snapshot.rb
|
81
81
|
- lib/mongoid-collection-snapshot/version.rb
|
82
82
|
- mongoid-collection-snapshot.gemspec
|
83
|
+
- spec/config/mongoid3.yml
|
84
|
+
- spec/config/mongoid4.yml
|
85
|
+
- spec/config/mongoid5.yml
|
86
|
+
- spec/config/mongoid6.yml
|
83
87
|
- spec/models/artist.rb
|
84
88
|
- spec/models/artwork.rb
|
85
89
|
- spec/models/average_price.rb
|
@@ -87,6 +91,7 @@ files:
|
|
87
91
|
- spec/models/multi_collection_snapshot.rb
|
88
92
|
- spec/models/partner.rb
|
89
93
|
- spec/mongoid/collection_snapshot_spec.rb
|
94
|
+
- spec/mongoid/multiple_databases_spec.rb
|
90
95
|
- spec/spec_helper.rb
|
91
96
|
homepage: http://github.com/mongoid/mongoid-collection-snapshot
|
92
97
|
licenses:
|
@@ -108,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
113
|
version: 1.3.6
|
109
114
|
requirements: []
|
110
115
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.6.
|
116
|
+
rubygems_version: 2.6.12
|
112
117
|
signing_key:
|
113
118
|
specification_version: 4
|
114
119
|
summary: Easy maintenence of collections of processed data in MongoDB with the Mongoid
|