infopark_cloud_connector 6.8.0.beta.200.713.e5c3150 → 6.8.0.beta.200.720.44fbabd

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,7 @@ module RailsConnector
8
8
  end
9
9
 
10
10
  def self.by_name(name)
11
- data = Workspace.current.attributes[name.to_s]
11
+ data = Revision.current.attributes[name.to_s]
12
12
  new(data) if data
13
13
  end
14
14
 
@@ -5,17 +5,17 @@ class Chain
5
5
  # the id of the content cache to use, or nil
6
6
  attr_reader :content_cache
7
7
 
8
- # a chain of patch operations that can be used to construct the target workspace
8
+ # a chain of patch operations that can be used to construct the target revision
9
9
  # each chain member is an array with two elements.
10
10
  # the first element denotes the patch type (-1, 1), where
11
- # 1 => apply the workspace
12
- # -1 => revert the workspace
13
- # and the second element is the workspace.
11
+ # 1 => apply the revision
12
+ # -1 => revert the revision
13
+ # and the second element is the revision.
14
14
  attr_reader :patches
15
15
 
16
- def self.build_for(workspace, content_cache = nil)
17
- if content_cache && content_cache.workspace
18
- patches = patches_to(workspace, content_cache.workspace)
16
+ def self.build_for(revision, content_cache = nil)
17
+ if content_cache && content_cache.revision
18
+ patches = patches_to(revision, content_cache.revision)
19
19
 
20
20
  if content_cache.transfer_target
21
21
  if patches.present? && patches.first.second == content_cache.transfer_target
@@ -27,7 +27,7 @@ class Chain
27
27
 
28
28
  new(content_cache, patches)
29
29
  else
30
- new(nil, patches_to(workspace))
30
+ new(nil, patches_to(revision))
31
31
  end
32
32
  end
33
33
 
@@ -44,7 +44,7 @@ class Chain
44
44
  @patches = patches
45
45
  end
46
46
 
47
- # performs a workspace aware query on the cms database.
47
+ # performs a revision aware query on the cms database.
48
48
  #
49
49
  # returns a hash of results from the query.
50
50
  # the keys are the criterion by which the query results are grouped (typically the OBJ ID).
@@ -57,23 +57,23 @@ class Chain
57
57
  version_map = result_map.merge(result_map) do |ignore, results|
58
58
  results.map {|row| Version.new(row) }
59
59
  end
60
- workspace_aware_results(version_map)
60
+ revision_aware_results(version_map)
61
61
  end
62
62
 
63
63
  private
64
64
 
65
- # calculate a list of patches to get to the destionation workspace.
65
+ # calculate a list of patches to get to the destionation revision.
66
66
  # if origin is given, the list will start at origin.
67
- # otherwise the list will start at the initial workspace.
67
+ # otherwise the list will start at the initial revision.
68
68
  def self.patches_to(destination, origin = nil)
69
69
  if destination.nil? && origin.nil?
70
70
  []
71
71
  elsif origin.nil? || origin.generation < destination.generation
72
- patches_to(destination.base_workspace, origin) + [[1, destination]]
72
+ patches_to(destination.base_revision, origin) + [[1, destination]]
73
73
  elsif destination.nil? || origin.generation > destination.generation
74
- [[-1, origin]] + patches_to(destination, origin.base_workspace)
74
+ [[-1, origin]] + patches_to(destination, origin.base_revision)
75
75
  elsif origin != destination
76
- [[-1, origin]] + patches_to(destination.base_workspace, origin.base_workspace) + [[1, destination]]
76
+ [[-1, origin]] + patches_to(destination.base_revision, origin.base_revision) + [[1, destination]]
77
77
  else # origin == destination
78
78
  []
79
79
  end
@@ -94,7 +94,7 @@ class Chain
94
94
  end
95
95
  if patches.present?
96
96
  result_map[:patches] = CmsBaseModel.query_index(:obj, index, query_options.merge({
97
- :range_value => workspace_range,
97
+ :range_value => revision_range,
98
98
  }))
99
99
  end
100
100
 
@@ -110,12 +110,12 @@ class Chain
110
110
  results << [1, result_map[:content_cache]]
111
111
  end
112
112
  if result_map[:patches].present?
113
- results_by_workspace = result_map[:patches].group_by do |version|
114
- version.workspace_id
113
+ results_by_revision = result_map[:patches].group_by do |version|
114
+ version.revision_id
115
115
  end
116
- patches.each do |(patch_diff_type, workspace)|
117
- results_for_workspace = results_by_workspace[workspace.id]
118
- results << [patch_diff_type, results_for_workspace] if results_for_workspace
116
+ patches.each do |(patch_diff_type, revision)|
117
+ results_for_revision = results_by_revision[revision.id]
118
+ results << [patch_diff_type, results_for_revision] if results_for_revision
119
119
  end
120
120
  end
121
121
 
@@ -140,8 +140,8 @@ class Chain
140
140
  end
141
141
 
142
142
  # apply the diff chain for each of obj
143
- # to determine which of them are included in the final workspace
144
- def workspace_aware_results(result_map)
143
+ # to determine which of them are included in the final revision
144
+ def revision_aware_results(result_map)
145
145
  result_index = {}
146
146
 
147
147
  # note: using merge as a map function for hashes
@@ -162,11 +162,11 @@ class Chain
162
162
 
163
163
  private
164
164
 
165
- def workspace_range
166
- @workspace_range ||=
165
+ def revision_range
166
+ @revision_range ||=
167
167
  begin
168
- sorted_keys = patches.map do |(type, workspace)|
169
- "#{"%010d" % workspace.generation}/#{workspace.id}"
168
+ sorted_keys = patches.map do |(type, revision)|
169
+ "#{"%010d" % revision.generation}/#{revision.id}"
170
170
  end.sort
171
171
  Range.new(sorted_keys.first, sorted_keys.last)
172
172
  end
@@ -7,21 +7,16 @@ class ContentCache < CmsBaseModel
7
7
  property :revision_id
8
8
  property :transferring_to
9
9
 
10
- # TODO remove when renaming workspace to revision in code
11
- def workspace_id
12
- revision_id
10
+ # returns the revision that is represented by this content cache.
11
+ # returns nil if the revision cannot be found.
12
+ def revision
13
+ @revision ||= Revision.find_by_id(revision_id)
13
14
  end
14
15
 
15
- # returns the workspace that is represented by this content cache.
16
- # returns nil if the workspace cannot be found.
17
- def workspace
18
- @workspace ||= Workspace.find_by_id(workspace_id)
19
- end
20
-
21
- # returns the workspace that this content cache is currently transferring to.
22
- # returns nil if no transfer is taking place or if the workspace cannot be found.
16
+ # returns the revision that this content cache is currently transferring to.
17
+ # returns nil if no transfer is taking place or if the revision cannot be found.
23
18
  def transfer_target
24
- @transfer_target ||= transferring_to ? Workspace.find_by_id(transferring_to) : nil
19
+ @transfer_target ||= transferring_to ? Revision.find_by_id(transferring_to) : nil
25
20
  end
26
21
  end
27
22
 
@@ -105,7 +105,7 @@ module RailsConnector
105
105
  # accepts the name of an "obj_by" - view and a list of keys.
106
106
  # returns a list of lists of Objs: a list of Objs for each given keys.
107
107
  def self.find_objs_by(view, keys) # :nodoc:
108
- Workspace.current.find_obj_data_by(view, keys).map do |list|
108
+ Revision.current.find_obj_data_by(view, keys).map do |list|
109
109
  list.map { |obj_data| Obj.instantiate(obj_data) }
110
110
  end
111
111
  end
@@ -438,7 +438,7 @@ module RailsConnector
438
438
  # Notice that the ruby class of this Obj instance will NOT change,
439
439
  # even if the obj_class in the database has changed.
440
440
  def reload
441
- obj_data = Workspace.current.find_obj_data_by(:id, [id.to_s]).first.first
441
+ obj_data = Revision.current.find_obj_data_by(:id, [id.to_s]).first.first
442
442
  update_data(obj_data["values"], obj_data)
443
443
  end
444
444
 
@@ -8,7 +8,7 @@ module RailsConnector
8
8
  end
9
9
 
10
10
  def self.by_name(name)
11
- data = Workspace.current.obj_classes[name.to_s]
11
+ data = Revision.current.obj_classes[name.to_s]
12
12
  new(data) if data
13
13
  end
14
14
 
@@ -0,0 +1,142 @@
1
+ #:enddoc:
2
+ module RailsConnector
3
+
4
+ class Revision < CmsBaseModel
5
+
6
+ self.key_prefix = "rev"
7
+
8
+ property :generation
9
+ property :base_revision_id
10
+ property :title
11
+ property :content_cache_id
12
+ property :attributes
13
+ property :obj_classes
14
+
15
+ # Selects the revision with the given id as current revision
16
+ def self.current=(revision)
17
+ @current = revision
18
+ end
19
+
20
+ def self.current
21
+ @current || default
22
+ end
23
+
24
+ def self.find_by_label(label_name)
25
+ workspace = Workspace.find(label_name)
26
+ find(workspace.revision_id)
27
+ end
28
+
29
+ def self.default
30
+ find_by_label("published")
31
+ end
32
+
33
+ def find_obj_data_by(index, keys)
34
+ find_obj_data_from_cache_or_database_by(index, keys)
35
+ end
36
+
37
+ def chain
38
+ @chain ||= Chain.build_for(self, content_cache)
39
+ end
40
+
41
+ def invalidate_chain
42
+ @chain = nil
43
+ end
44
+
45
+ # returns the base revision or nil for an initial revision
46
+ def base_revision
47
+ @base_revision ||= base_revision_id ? Revision.find(base_revision_id) : nil
48
+ end
49
+
50
+ # returns the content cache to be used with this revision or nil if not available
51
+ def content_cache
52
+ if content_cache_id
53
+ if @content_cache && content_cache_id == @content_cache.id
54
+ @content_cache
55
+ else
56
+ @content_cache = ContentCache.find_by_id(content_cache_id)
57
+ end
58
+ end
59
+ end
60
+
61
+ def inspect
62
+ "<#{self.class} id=\"#{id}\" title=\"#{title}\">"
63
+ end
64
+
65
+ private
66
+
67
+ COMPOUND_KEY_INDICES = [:ppath].freeze
68
+
69
+ def find_obj_data_from_database_by(index, keys)
70
+ return [] if keys.blank?
71
+ instrumenter = ActiveSupport::Notifications.instrumenter
72
+ instrumenter.instrument(
73
+ "cms_load.rails_connector", :name => "Obj Load", :index => index, :keys => keys
74
+ ) do
75
+ keys.map do |key|
76
+ results = chain.query(index, key, COMPOUND_KEY_INDICES.include?(index))
77
+ results.values.map { |row| extract_obj_data(row) }
78
+ end
79
+ end
80
+ end
81
+
82
+ def find_obj_data_from_cache_or_database_by(index, keys)
83
+ # load results from cache
84
+ keys_from_database = []
85
+ results_from_cache = keys.map do |key|
86
+ Cache.load([:obj, index, key]).tap do |objs|
87
+ keys_from_database << key unless objs
88
+ end
89
+ end
90
+
91
+ # load cache misses from database and store them in cache
92
+ results_from_database = find_obj_data_from_database_by(index, keys_from_database)
93
+ keys_from_database.each_with_index do |key, key_number|
94
+ store_obj_data_list_in_cache(index, key, results_from_database[key_number])
95
+ end
96
+
97
+ # combine the results
98
+ results_from_cache.map do |objs_from_cache|
99
+ objs_from_cache || results_from_database.shift
100
+ end
101
+ end
102
+
103
+ UNIQUE_INDICES = [:id, :path, :permalink].freeze
104
+ OBJ_PROPERTY_VALUE_TO_RANGE_VALUE_CONVERSIONS = {
105
+ :path => PathConversion.method(:path_from_list)
106
+ }.freeze
107
+
108
+ def store_obj_data_list_in_cache(index, key, obj_data_list)
109
+ obj_data_list.each do |obj_data|
110
+ values = obj_data["values"]
111
+ UNIQUE_INDICES.each do |unique_index|
112
+ index_value = values["_#{unique_index}"]
113
+ if (converter = OBJ_PROPERTY_VALUE_TO_RANGE_VALUE_CONVERSIONS[unique_index])
114
+ index_value = converter.call(index_value)
115
+ end
116
+ store_item_in_cache(unique_index, index_value, [obj_data])
117
+ end
118
+ end
119
+ unless UNIQUE_INDICES.include?(index)
120
+ store_item_in_cache(index, key, obj_data_list)
121
+ end
122
+ end
123
+
124
+ def store_item_in_cache(index, key, item)
125
+ Cache.store([:obj, index, key], item)
126
+ end
127
+
128
+ def extract_obj_data(data)
129
+ {
130
+ "values" => data["values"].merge(
131
+ "_id" => data["obj_id"],
132
+ "_obj_type" => data["obj_type"],
133
+ "_obj_class" => data["obj_class"]["name"]
134
+ ),
135
+ "attributes" => data["attributes"],
136
+ "ext_ref" => data["ext_ref"],
137
+ }
138
+ end
139
+
140
+ end
141
+
142
+ end
@@ -10,7 +10,7 @@ class Version
10
10
  @doc["obj_id"]
11
11
  end
12
12
 
13
- def workspace_id
13
+ def revision_id
14
14
  @doc["revision_id"]
15
15
  end
16
16
 
@@ -1,147 +1,11 @@
1
1
  #:enddoc:
2
2
  module RailsConnector
3
3
 
4
- class Workspace < CmsBaseModel
4
+ class Workspace < CmsBaseModel
5
+ self.key_prefix = "ws"
5
6
 
6
- self.key_prefix = "rev"
7
+ property :revision_id
7
8
 
8
- property :generation
9
- property :base_revision_id
10
- property :title
11
- property :content_cache_id
12
- property :attributes
13
- property :obj_classes
14
-
15
- # TODO remove when renaming workspace to revision in code
16
- def base_workspace_id
17
- base_revision_id
18
- end
19
-
20
- # Selects the workspace with the given id as current workspace
21
- def self.current=(workspace)
22
- @current = workspace
23
- end
24
-
25
- def self.current
26
- @current || Workspace.default
27
- end
28
-
29
- def self.find_by_label(label_name)
30
- label = WorkspaceLabel.find(label_name)
31
- find(label.workspace_id)
32
- end
33
-
34
- def self.default
35
- Workspace.find_by_label("published")
36
- end
37
-
38
- def find_obj_data_by(index, keys)
39
- find_obj_data_from_cache_or_database_by(index, keys)
40
- end
41
-
42
- def chain
43
- @chain ||= Chain.build_for(self, content_cache)
44
- end
45
-
46
- def invalidate_chain
47
- @chain = nil
48
- end
49
-
50
- # returns the base workspace or nil for an initial workspace
51
- def base_workspace
52
- @base_workspace ||= base_workspace_id ? Workspace.find(base_workspace_id) : nil
53
- end
54
-
55
- # returns the content cache to be used with this workspace or nil if not available
56
- def content_cache
57
- if content_cache_id
58
- if @content_cache && content_cache_id == @content_cache.id
59
- @content_cache
60
- else
61
- @content_cache = ContentCache.find_by_id(content_cache_id)
62
- end
63
- end
64
- end
65
-
66
- def inspect
67
- "<#{self.class} id=\"#{id}\" title=\"#{title}\">"
68
- end
69
-
70
- private
71
-
72
- COMPOUND_KEY_INDICES = [:ppath].freeze
73
-
74
- def find_obj_data_from_database_by(index, keys)
75
- return [] if keys.blank?
76
- instrumenter = ActiveSupport::Notifications.instrumenter
77
- instrumenter.instrument(
78
- "cms_load.rails_connector", :name => "Obj Load", :index => index, :keys => keys
79
- ) do
80
- keys.map do |key|
81
- results = chain.query(index, key, COMPOUND_KEY_INDICES.include?(index))
82
- results.values.map { |row| extract_obj_data(row) }
83
- end
84
- end
85
- end
86
-
87
- def find_obj_data_from_cache_or_database_by(index, keys)
88
- # load results from cache
89
- keys_from_database = []
90
- results_from_cache = keys.map do |key|
91
- Cache.load([:obj, index, key]).tap do |objs|
92
- keys_from_database << key unless objs
93
- end
94
- end
95
-
96
- # load cache misses from database and store them in cache
97
- results_from_database = find_obj_data_from_database_by(index, keys_from_database)
98
- keys_from_database.each_with_index do |key, key_number|
99
- store_obj_data_list_in_cache(index, key, results_from_database[key_number])
100
- end
101
-
102
- # combine the results
103
- results_from_cache.map do |objs_from_cache|
104
- objs_from_cache || results_from_database.shift
105
- end
106
- end
107
-
108
- UNIQUE_INDICES = [:id, :path, :permalink].freeze
109
- OBJ_PROPERTY_VALUE_TO_RANGE_VALUE_CONVERSIONS = {
110
- :path => PathConversion.method(:path_from_list)
111
- }.freeze
112
-
113
- def store_obj_data_list_in_cache(index, key, obj_data_list)
114
- obj_data_list.each do |obj_data|
115
- values = obj_data["values"]
116
- UNIQUE_INDICES.each do |unique_index|
117
- index_value = values["_#{unique_index}"]
118
- if (converter = OBJ_PROPERTY_VALUE_TO_RANGE_VALUE_CONVERSIONS[unique_index])
119
- index_value = converter.call(index_value)
120
- end
121
- store_item_in_cache(unique_index, index_value, [obj_data])
122
- end
123
- end
124
- unless UNIQUE_INDICES.include?(index)
125
- store_item_in_cache(index, key, obj_data_list)
126
- end
127
- end
128
-
129
- def store_item_in_cache(index, key, item)
130
- Cache.store([:obj, index, key], item)
131
- end
132
-
133
- def extract_obj_data(data)
134
- {
135
- "values" => data["values"].merge(
136
- "_id" => data["obj_id"],
137
- "_obj_type" => data["obj_type"],
138
- "_obj_class" => data["obj_class"]["name"]
139
- ),
140
- "attributes" => data["attributes"],
141
- "ext_ref" => data["ext_ref"],
142
- }
143
- end
144
-
145
- end
9
+ end
146
10
 
147
11
  end
@@ -11,7 +11,7 @@ class WorkspaceSelectionMiddleware
11
11
 
12
12
  def call(env)
13
13
  handle_workspace_parameter(env)
14
- Workspace.current = workspace_to_show(env)
14
+ Revision.current = workspace_to_show(env)
15
15
 
16
16
  @app.call(env)
17
17
  end
@@ -30,9 +30,9 @@ class WorkspaceSelectionMiddleware
30
30
 
31
31
  def workspace_to_show(env)
32
32
  if preview_workspace = session(env)[CURRENT_WORKSPACE_SESSION_KEY]
33
- Workspace.find(preview_workspace)
33
+ Revision.find(preview_workspace)
34
34
  else
35
- Workspace.default
35
+ Revision.default
36
36
  end
37
37
  end
38
38
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infopark_cloud_connector
3
3
  version: !ruby/object:Gem::Version
4
- hash: 2363298151
4
+ hash: -23731721781
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 6
@@ -9,12 +9,10 @@ version: !ruby/object:Gem::Version
9
9
  - 0
10
10
  - beta
11
11
  - 200
12
- - 713
13
- - e
14
- - 5
15
- - c
16
- - 3150
17
- version: 6.8.0.beta.200.713.e5c3150
12
+ - 720
13
+ - 44
14
+ - fbabd
15
+ version: 6.8.0.beta.200.720.44fbabd
18
16
  platform: ruby
19
17
  authors:
20
18
  - Infopark AG
@@ -22,7 +20,7 @@ autorequire:
22
20
  bindir: bin
23
21
  cert_chain: []
24
22
 
25
- date: 2012-06-29 00:00:00 +02:00
23
+ date: 2012-07-02 00:00:00 +02:00
26
24
  default_executable:
27
25
  dependencies:
28
26
  - !ruby/object:Gem::Dependency
@@ -63,19 +61,17 @@ dependencies:
63
61
  requirements:
64
62
  - - "="
65
63
  - !ruby/object:Gem::Version
66
- hash: 2363298151
64
+ hash: -23731721781
67
65
  segments:
68
66
  - 6
69
67
  - 8
70
68
  - 0
71
69
  - beta
72
70
  - 200
73
- - 713
74
- - e
75
- - 5
76
- - c
77
- - 3150
78
- version: 6.8.0.beta.200.713.e5c3150
71
+ - 720
72
+ - 44
73
+ - fbabd
74
+ version: 6.8.0.beta.200.720.44fbabd
79
75
  version_requirements: *id003
80
76
  name: kvom
81
77
  prerelease: false
@@ -114,10 +110,10 @@ files:
114
110
  - lib/rails_connector/path_conversion.rb
115
111
  - lib/rails_connector/permission.rb
116
112
  - lib/rails_connector/rack_middlewares.rb
113
+ - lib/rails_connector/revision.rb
117
114
  - lib/rails_connector/s3_blob.rb
118
115
  - lib/rails_connector/version.rb
119
116
  - lib/rails_connector/workspace.rb
120
- - lib/rails_connector/workspace_label.rb
121
117
  - lib/rails_connector/workspace_selection_middleware.rb
122
118
  - README
123
119
  has_rdoc: true
@@ -1,15 +0,0 @@
1
- #:enddoc:
2
- module RailsConnector
3
-
4
- class WorkspaceLabel < CmsBaseModel
5
- self.key_prefix = "ws"
6
-
7
- property :revision_id
8
-
9
- # TODO remove when renaming workspace to revision in code
10
- def workspace_id
11
- revision_id
12
- end
13
- end
14
-
15
- end