infopark_cloud_connector 6.8.3.115.227021242 → 6.8.3.174.51542603

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +1,15 @@
1
1
  require 'json'
2
2
  require 'ostruct'
3
- require 'kvom'
4
3
 
5
4
  module RailsConnector
6
5
  # The CMS file class
7
6
  # @api public
8
7
  class BasicObj
9
8
  extend ActiveModel::Naming
10
- include Kvom::ModelIdentity
11
9
 
12
10
  include DateAttribute
13
11
  include SEO
12
+ include ModelIdentity
14
13
 
15
14
  # Create a new Obj instance with the given values and attributes.
16
15
  # Normally this method should not be used.
@@ -1,81 +1,48 @@
1
- require "aws-sdk"
2
-
3
1
  module RailsConnector
4
2
 
3
+ # TODO Caching:
4
+ # unlimited urls: ewig
5
+ # limited urls: zeitlimit - x (x fuer mindestverwendbarkeitszeit)
5
6
  class Blob
6
7
 
7
8
  class << self
8
- def find(id)
9
- new(blob_class.find(id))
10
- end
11
-
12
- def config
13
- @config or raise "Blob storage has not been configured yet"
14
- end
15
-
16
- def configure(spec)
17
- @config = spec.symbolize_keys
18
- @blob_class = nil
19
- end
20
-
21
- def blob_class
22
- @blob_class ||= blob_class_from_config
23
- end
24
9
 
25
- # for testing purposes
26
- def reset_blob_class_cache
27
- @blob_class = nil
10
+ def configure(config)
28
11
  end
29
12
 
30
- def unconfigure
31
- @config = nil
13
+ def find(id)
14
+ new(id)
32
15
  end
33
16
 
34
- private
35
-
36
- def blob_class_from_config
37
- blob_class =
38
- case config[:type].to_sym
39
- when :s3
40
- S3Blob
41
- when :service
42
- ServiceBlob
43
- else
44
- raise "Unsupported blob storage type #{config[:type]}"
45
- end
46
- blob_class.configure(config)
47
- blob_class
48
- end
49
17
  end
50
18
 
51
- def initialize(blob_instance)
52
- @instance = blob_instance
53
- end
19
+ attr_reader :id
54
20
 
55
- def id
56
- instance.id
21
+ def initialize(id)
22
+ @id = id
57
23
  end
58
24
 
59
25
  def url
60
- instance.url
61
- end
62
-
63
- def meta_url
64
- instance.meta_url
26
+ raw_data["url"]
65
27
  end
66
28
 
67
29
  def content_type
68
- instance.content_type
30
+ meta_data[:content_type]
69
31
  end
70
32
 
71
33
  def length
72
- instance.length
34
+ meta_data[:content_length].to_i
73
35
  end
74
36
 
75
37
  private
76
38
 
77
- attr_reader :instance
39
+ def raw_data
40
+ @raw_data ||= CmsBackend.find_blob_data_by_id(id)
41
+ end
78
42
 
43
+ def meta_data
44
+ @meta_data ||= RestClient.head(raw_data["meta_url"]).headers
45
+ end
79
46
  end
80
47
 
81
- end # module RailsConnector
48
+ end
@@ -10,7 +10,6 @@ class CacheMiddleware
10
10
  @app.call(env)
11
11
  ensure
12
12
  CmsBackend.end_caching
13
- DictStorage.clear_first_level_cache
14
13
  end
15
14
  end
16
15
 
@@ -1,39 +1,201 @@
1
+ require 'rest_client'
2
+
1
3
  module RailsConnector
2
4
 
5
+ class ContentServiceObjQueries
6
+ def initialize(queries)
7
+ @queries = queries
8
+ @open_queries = queries.dup
9
+ @results = {}
10
+ end
11
+
12
+ def open_queries
13
+ @open_queries[0..99]
14
+ end
15
+
16
+ def handle_response(response)
17
+ objs = {}
18
+ response["objs"].each do |obj|
19
+ objs[obj["_id"].first] = obj
20
+ end
21
+
22
+ queries_to_delete = []
23
+ response["results"].each_with_index do |response, i|
24
+ query = @open_queries[i]
25
+ if response["continuation_handle"]
26
+ query[:continuation_handle] = response["continuation_handle"]
27
+ else
28
+ queries_to_delete << i
29
+ end
30
+ result = (@results[query.__id__] ||= [])
31
+ response["refs"].each do |obj_ref|
32
+ id = obj_ref["id"]
33
+ # TODO fetch missing ObjData from Service
34
+ result << (objs[id] or raise "Data for Obj with id #{id} missing!")
35
+ end
36
+ end
37
+ queries_to_delete.reverse_each {|i| @open_queries.delete_at(i) }
38
+ end
39
+
40
+ def results
41
+ @queries.map {|query| @results[query.__id__] || [] }
42
+ end
43
+
44
+ def finished?
45
+ open_queries.empty?
46
+ end
47
+ end
48
+
49
+ # connects the cloud connector to the connector service
3
50
  class CmsBackend
51
+ BLOB_DATA_CACHE_PREFIX = 'blob_data'.freeze
52
+ VALID_INDEX_NAMES = %w[id path ppath permalink].freeze
4
53
 
5
- def self.current
6
- @current ||= begin
7
- RailsConnector::Configuration.content_service ? ServiceCmsBackend.new : DynamoCmsBackend.new
54
+ class << self
55
+ def instance
56
+ @instance ||= new
8
57
  end
58
+
59
+ delegate :begin_caching, :end_caching, :caching?, :query_counter, :find_workspace_data_by_id,
60
+ :find_obj_data_by, :find_blob_data_by_id, to: :instance
61
+ end
62
+
63
+ def initialize
64
+ @query_counter = 0
9
65
  end
10
66
 
11
- def self.begin_caching
12
- current.begin_caching
67
+ def begin_caching
68
+ @caching = true
13
69
  end
14
70
 
15
- def self.end_caching
16
- current.end_caching
71
+ def end_caching
72
+ CmsCacheStorage.cache.clear
73
+ @caching = false
17
74
  end
18
75
 
19
- def self.find_obj_data_by(workspace_data, index, keys)
20
- current.find_obj_data_by(workspace_data, index, keys)
76
+ def caching?
77
+ !!@caching
78
+ end
79
+
80
+ def query_counter
81
+ @query_counter
82
+ end
83
+
84
+ def find_workspace_data_by_id(id)
85
+ from_content_state_id = ContentStateCaching.find_content_state_id(id)
86
+ request_params = {:workspace_id => id}
87
+ request_params[:content_state_id] = from_content_state_id if from_content_state_id
88
+ raw_data = ContentService.query('workspaces/query', request_params)
89
+ if raw_workspace_data = raw_data['workspace']
90
+ workspace_data = WorkspaceDataFromService.new(raw_workspace_data)
91
+ if from_content_state_id != workspace_data.content_state_id
92
+ ContentStateCaching.store_content_state(workspace_data)
93
+ ContentStateCaching.store_content_state_id(workspace_data.id,
94
+ workspace_data.content_state_id)
95
+ end
96
+ workspace_data
97
+ end
21
98
  end
22
99
 
23
- def self.find_workspace_data_by_id(id)
24
- current.find_workspace_data_by_id(id)
100
+ def find_obj_data_by(workspace_data, index, keys)
101
+ index = index.to_s
102
+ assert_valid_index_name(index)
103
+ raw_data = find_raw_data_from_cache_or_database_by(workspace_data, index, keys)
104
+ raw_data.map do |raw_list|
105
+ raw_list.map do |raw_obj_data|
106
+ ObjDataFromService.new(raw_obj_data)
107
+ end
108
+ end
109
+ end
110
+
111
+ def find_blob_data_by_id(id)
112
+ cache_key = "#{BLOB_DATA_CACHE_PREFIX}/#{id}"
113
+ if data_from_cache = CmsCacheStorage.cache.read(cache_key)
114
+ data_from_cache
115
+ else
116
+ data_from_database = find_blob_data_from_database_by(id)
117
+ if maxage = data_from_database['maxage']
118
+ CmsCacheStorage.cache.write(cache_key, data_from_database, :expires_in => maxage)
119
+ end
120
+ data_from_database
121
+ end
122
+ end
123
+
124
+ private
125
+
126
+ def find_raw_data_from_cache_or_database_by(workspace_data, index, keys)
127
+ keys_from_database = []
128
+ # load results from cache
129
+ results_from_cache = keys.map do |key|
130
+ find_raw_data_from_cache_by(workspace_data, index, key).tap do |objs|
131
+ keys_from_database << key unless objs
132
+ end
133
+ end
134
+
135
+ # load cache misses from database and store them in cache
136
+ results_from_database =
137
+ find_raw_data_from_database_by(workspace_data, index, keys_from_database)
138
+ keys_from_database.each_with_index do |key, key_number|
139
+ store_raw_data_list_in_cache(workspace_data, index, key, results_from_database[key_number])
140
+ end
141
+
142
+ # combine the results
143
+ results_from_cache.map do |objs_from_cache|
144
+ objs_from_cache || results_from_database.shift
145
+ end
146
+ end
147
+
148
+ def find_raw_data_from_cache_by(workspace_data, index, key)
149
+ ContentStateCaching.find_obj_data(workspace_data, index, key) if caching?
150
+ end
151
+
152
+ def find_raw_data_from_database_by(workspace_data, index, keys)
153
+ return [] if keys.blank?
154
+ instrumenter = ActiveSupport::Notifications.instrumenter
155
+ instrumenter.instrument(
156
+ "cms_load.rails_connector", :name => "Obj Load", :index => index, :keys => keys
157
+ ) do
158
+ @query_counter += 1
159
+ queries = ContentServiceObjQueries.new(keys.map {|key| {:type => index, :param => key} })
160
+ until queries.finished?
161
+ queries.handle_response(ContentService.query(
162
+ "objs/query",
163
+ :queries => queries.open_queries,
164
+ :workspace_id => workspace_data.id,
165
+ :revision_id => workspace_data.revision_id
166
+ ))
167
+ end
168
+ queries.results
169
+ end
170
+ end
171
+
172
+ UNIQUE_INDICES = [:id, :path, :permalink].freeze
173
+
174
+ def store_raw_data_list_in_cache(workspace_data, index, key, raw_data_list)
175
+ raw_data_list.each do |values|
176
+ UNIQUE_INDICES.each do |unique_index|
177
+ unique_index_values = values["_#{unique_index}"]
178
+ if unique_index_values.present?
179
+ store_item_in_cache(workspace_data, unique_index, unique_index_values.first, [values])
180
+ end
181
+ end
182
+ end
183
+ unless UNIQUE_INDICES.include?(index)
184
+ store_item_in_cache(workspace_data, index, key, raw_data_list)
185
+ end
25
186
  end
26
187
 
27
- def self.caching?
28
- current.caching?
188
+ def store_item_in_cache(workspace_data, index, key, item)
189
+ ContentStateCaching.store_obj_data(workspace_data, index, key, item)
29
190
  end
30
191
 
31
- def self.query_counter
32
- current.query_counter
192
+ def find_blob_data_from_database_by(id)
193
+ @query_counter += 1
194
+ ContentService.query('blobs/query', :blob_ids => [id])['blobs'][id]
33
195
  end
34
196
 
35
- def self.find_blob_data_by_id(id)
36
- current.find_blob_data_by_id(id)
197
+ def assert_valid_index_name(index)
198
+ raise ArgumentError, "invalid index name '#{index}'" unless VALID_INDEX_NAMES.include?(index)
37
199
  end
38
200
 
39
201
  end
@@ -0,0 +1,13 @@
1
+ module RailsConnector
2
+
3
+ module ModelIdentity
4
+ def ==(other)
5
+ other.equal?(self) || other.instance_of?(self.class) && other.id == id
6
+ end
7
+
8
+ alias_method :eql?, :==
9
+
10
+ delegate :hash, to: :id
11
+ end
12
+
13
+ end
@@ -2,7 +2,8 @@ module RailsConnector
2
2
 
3
3
  class Workspace
4
4
  extend ActiveModel::Naming
5
- include Kvom::ModelIdentity
5
+
6
+ include ModelIdentity
6
7
 
7
8
  def self.current=(workspace_or_proc)
8
9
  @current = workspace_or_proc
@@ -44,16 +45,6 @@ class Workspace
44
45
  @workspace_data
45
46
  end
46
47
 
47
- # only available with direct access to dynamo
48
- def revision
49
- @workspace_data.revision
50
- end
51
-
52
- # only available with direct access to dynamo
53
- def content_cache_id=(id)
54
- @workspace_data.content_cache_id = id
55
- end
56
-
57
48
  def published?
58
49
  self.id == 'published'
59
50
  end
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
- version: 6.8.3.115.227021242
4
+ version: 6.8.3.174.51542603
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-01 00:00:00.000000000 Z
12
+ date: 2013-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: aws-sdk
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 1.3.6
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 1.3.6
30
14
  - !ruby/object:Gem::Dependency
31
15
  name: rest-client
32
16
  requirement: !ruby/object:Gem::Requirement
@@ -75,22 +59,6 @@ dependencies:
75
59
  - - ~>
76
60
  - !ruby/object:Gem::Version
77
61
  version: 2.3.2
78
- - !ruby/object:Gem::Dependency
79
- name: kvom
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - '='
84
- - !ruby/object:Gem::Version
85
- version: 6.8.3.115.227021242
86
- type: :runtime
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - '='
92
- - !ruby/object:Gem::Version
93
- version: 6.8.3.115.227021242
94
62
  description: The Cloud Connector for Infopark CMS Fiona enables you to develop modern,
95
63
  dynamic Web 2.0 applications using Ruby on Rails and at the same time display CMS
96
64
  managed content.
@@ -121,15 +89,12 @@ files:
121
89
  - lib/rails_connector/blob.rb
122
90
  - lib/rails_connector/cache.rb
123
91
  - lib/rails_connector/cache_middleware.rb
124
- - lib/rails_connector/chain.rb
125
92
  - lib/rails_connector/client_error.rb
126
93
  - lib/rails_connector/cloud_engine.rb
127
94
  - lib/rails_connector/cms_api_search_request.rb
128
95
  - lib/rails_connector/cms_backend.rb
129
- - lib/rails_connector/cms_base_model.rb
130
96
  - lib/rails_connector/cms_cache_storage.rb
131
97
  - lib/rails_connector/cms_rest_api.rb
132
- - lib/rails_connector/content_cache.rb
133
98
  - lib/rails_connector/content_conversion.rb
134
99
  - lib/rails_connector/content_service.rb
135
100
  - lib/rails_connector/content_state.rb
@@ -138,8 +103,6 @@ files:
138
103
  - lib/rails_connector/controller_runtime.rb
139
104
  - lib/rails_connector/date_attribute.rb
140
105
  - lib/rails_connector/default_search_request.rb
141
- - lib/rails_connector/dict_storage.rb
142
- - lib/rails_connector/dynamo_cms_backend.rb
143
106
  - lib/rails_connector/elasticsearch_request.rb
144
107
  - lib/rails_connector/errors.rb
145
108
  - lib/rails_connector/link.rb
@@ -152,22 +115,14 @@ files:
152
115
  - lib/rails_connector/migrations/migration_store.rb
153
116
  - lib/rails_connector/migrations/migrator.rb
154
117
  - lib/rails_connector/migrations/workspace_lock.rb
118
+ - lib/rails_connector/model_identity.rb
155
119
  - lib/rails_connector/named_link.rb
156
120
  - lib/rails_connector/obj_data.rb
157
- - lib/rails_connector/obj_data_from_database.rb
158
121
  - lib/rails_connector/obj_data_from_hash.rb
159
122
  - lib/rails_connector/obj_data_from_service.rb
160
123
  - lib/rails_connector/obj_search_enumerator.rb
161
- - lib/rails_connector/path_conversion.rb
162
- - lib/rails_connector/permission.rb
163
124
  - lib/rails_connector/rack_middlewares.rb
164
- - lib/rails_connector/revision.rb
165
- - lib/rails_connector/s3_blob.rb
166
- - lib/rails_connector/service_blob.rb
167
- - lib/rails_connector/service_cms_backend.rb
168
- - lib/rails_connector/version.rb
169
125
  - lib/rails_connector/workspace.rb
170
- - lib/rails_connector/workspace_data_from_database.rb
171
126
  - lib/rails_connector/workspace_data_from_service.rb
172
127
  - lib/rails_connector/workspace_selection_middleware.rb
173
128
  - lib/tasks/migration.rake
@@ -185,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
140
  version: '0'
186
141
  segments:
187
142
  - 0
188
- hash: 723525395
143
+ hash: 676465587
189
144
  required_rubygems_version: !ruby/object:Gem::Requirement
190
145
  none: false
191
146
  requirements: