lib/scrivito/cms_backend.rb in scrivito_sdk-1.4.3 vs lib/scrivito/cms_backend.rb in scrivito_sdk-1.5.0.rc1
- old
+ new
@@ -85,11 +85,11 @@
end
end
def self.search_objs(workspace, params)
cache_index = 'search'
- cache_key = params.to_param
+ cache_key = search_params_cache_key(params)
cache = Backend::ObjDataCache.view_for_revision(workspace.revision)
if hit = cache.read_index(cache_index, cache_key)
return hit
end
@@ -98,32 +98,24 @@
persistent = !result.delete('tentative')
cache.write_index_not_updatable(cache_index, cache_key, result, persistent: persistent)
result
end
- def self.create_obj(workspace_id, attributes)
- write_obj(:post, "/workspaces/#{workspace_id}/objs", attributes)
- end
-
- def self.update_obj(workspace_id, obj_id, attributes)
- write_obj(:put, "/workspaces/#{workspace_id}/objs/#{obj_id}", attributes)
- end
-
# For test purpose only.
def self.query_counter
@query_counter
end
# For test purpose only.
def self.reset_query_counter!
@query_counter = 0
end
- def self.write_obj(verb, path, attributes)
- Backend::ObjDataFromRest.new(CmsRestApi.task_unaware_request(verb, path, attributes))
+ def self.write_obj(workspace_id, obj_id, attributes)
+ path = "/workspaces/#{workspace_id}/objs/#{obj_id}"
+ Backend::ObjDataFromRest.new(CmsRestApi.task_unaware_request(:put, path, attributes))
end
- private_class_method :write_obj
def self.update_workspace_cache(id, cached_data_tag, workspace, options)
if workspace
workspace_data = workspace
else
@@ -165,10 +157,13 @@
end
end
private_class_method :update_obj_cache
def self.request_search_result_from_backend(workspace, params)
+ @query_counter ||= 0
+ @query_counter += 1
+
params = params.merge(consistent_with: workspace.content_state_id)
CmsRestApi.get("workspaces/#{workspace.id}/objs/search", params)
end
private_class_method :request_search_result_from_backend
@@ -213,9 +208,23 @@
end
cache_key
end
private_class_method :blob_data_cache_key
+
+ def self.search_params_cache_key(params)
+ MultiJson.encode(normalize_search_param(params))
+ end
+ private_class_method :search_params_cache_key
+
+ def self.normalize_search_param(param)
+ case param
+ when Array then param.map { |v| normalize_search_param(v) }
+ when Hash then param.map { |k, v| [k.to_s, normalize_search_param(v)] }.sort
+ else param
+ end
+ end
+ private_class_method :normalize_search_param
def self.normalize_blob_id(id)
CmsRestApi.normalize_path_component(id)
end
private_class_method :normalize_blob_id