lib/scrivito/cms_backend.rb in scrivito_sdk-0.60.0 vs lib/scrivito/cms_backend.rb in scrivito_sdk-0.65.0.rc1

- old
+ new

@@ -53,12 +53,15 @@ def instance @instance ||= new end end + attr_accessor :die_content_service + def initialize @query_counter = 0 + @caching = true end def begin_caching @caching = true end @@ -66,10 +69,14 @@ def end_caching CmsDataCache.cache.clear @caching = false end + def clear_cache + CmsDataCache.cache.clear + end + def caching? !!@caching end def query_counter @@ -80,10 +87,37 @@ def reset_query_counter! @query_counter = 0 end def find_workspace_data_by_id(id) + if die_content_service + from_csid = CmsDataCache.read_workspace_csid(id) + + changes = CmsRestApi.get("/workspaces/#{id}/changes", from: from_csid) + + objs = changes["objs"] + if objs.present? + if objs != "*" + last_state = Backend::ContentStateNode.find(from_csid) + + successor_state = changes["to"] + current_state = last_state.create_successor(successor_state, objs) + end + + # TODO what if workspace data is missing? + # have the backend team include a new key `current` + current_csid = changes["workspace"]["content_state_id"] + CmsDataCache.write_workspace_csid(id, current_csid) + end + + # TODO what if workspace data is missing? + # implement workspace data caching + workspace_data = changes["workspace"] + + return WorkspaceData.new(workspace_data) + end + workspace_data_from_cache = WorkspaceDataFromService.find_from_cache(id) from_content_state_id = workspace_data_from_cache.try(:content_state_id) request_params = {:workspace_id => id} request_params[:content_state_id] = from_content_state_id if from_content_state_id @@ -99,21 +133,41 @@ ContentService.query('workspaces/query', request_params) end if raw_workspace_data = raw_data['workspace'] workspace_data = WorkspaceDataFromService.new(raw_workspace_data) - workspace_data.store_in_cache if from_content_state_id != workspace_data.content_state_id + if from_content_state_id != workspace_data.content_state_id + workspace_data.store_in_cache_and_create_content_state + end workspace_data end end def find_obj_data_by(revision, index, keys) - find_obj_data_filtering_deleted_by(revision, index, keys, false) - end + index = index.to_s - def find_obj_data_including_deleted_by(revision, index, keys) - find_obj_data_filtering_deleted_by(revision, index, keys, true) + if die_content_service + obj_datas = + if index == "id" + obj_datas = Backend::ObjLoad.load(revision, keys) + obj_datas.map { |obj_data| obj_data ? [obj_data] : [] } + else + index_implementation = Backend::Index.by_name(index) + Backend::ObjQuery.query(revision, index_implementation, keys) + end + + return obj_datas + end + + assert_valid_index_name(index) + raw_data = find_raw_data_from_cache_or_database_by(revision, index, keys) + + raw_data.map do |raw_result| + raw_result.each_with_object([]) do |raw_data, result| + result << ObjDataFromService.new(raw_data) + end + end end def find_blob_data(id, access, verb) id = Addressable::URI.normalize_component(id, Addressable::URI::CharacterClasses::UNRESERVED) if blob_data = fetch_blob_data_from_cache(id, access, verb) @@ -134,10 +188,15 @@ blob_metadata end end def search_objs(workspace, params) + if die_content_service + # TODO caching + return request_search_result_from_backend(workspace, params) + end + content_state = workspace.revision.content_state cache_index = 'search' cache_key = params.to_param if result = fetch_search_result_from_cache(content_state, cache_index, cache_key) @@ -245,22 +304,9 @@ CmsDataCache.cache.write(blob_metadata_cache_key(id), blob_metadata, max_age) end def blob_metadata_cache_key(id) "blob_metadata/#{id}" - end - - def find_obj_data_filtering_deleted_by(revision, index, keys, include_deleted) - index = index.to_s - assert_valid_index_name(index) - raw_data = find_raw_data_from_cache_or_database_by(revision, index, keys) - - raw_data.map do |raw_result| - raw_result.each_with_object([]) do |raw_data, result| - next if raw_data['_modification'] == ['deleted'] && !include_deleted - result << ObjDataFromService.new(raw_data) - end - end end def find_raw_data_from_cache_or_database_by(revision, index, keys) keys_from_database = [] # load results from cache