lib/scrivito/cms_backend.rb in scrivito_sdk-0.17.0 vs lib/scrivito/cms_backend.rb in scrivito_sdk-0.18.0

- old
+ new

@@ -121,10 +121,64 @@ end data_from_database end end + def search_objs(workspace, params) + 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) + result + else + request_search_result_from_backend(workspace, params).tap do |result| + store_search_result_in_cache(content_state, cache_index, cache_key, result) + end + end + end + + def find_obj_class_data_by_name(revision, name) + find_all_obj_class_data(revision).find { |obj_class_data| obj_class_data.name == name } + end + + def find_all_obj_class_data(revision) + content_state = revision.content_state + if obj_classes_data = fetch_obj_classes_data_from_cache(content_state) + obj_classes_data + else + request_obj_classes_data_from_backend(revision).tap do |obj_classes_data| + store_obj_classes_data_in_cache(content_state, obj_classes_data) + end + end + end + private + + def fetch_obj_classes_data_from_cache(content_state) + ContentStateCaching.find_obj_classes_data(content_state) if caching? + end + + def request_obj_classes_data_from_backend(revision) + response = CmsRestApi.get("revisions/#{revision.id}/obj_classes", include_inactive: true) + response['results'].map { |raw_data| ObjClassData.new(raw_data) } + end + + def store_obj_classes_data_in_cache(content_state, obj_classes_data) + ContentStateCaching.store_obj_classes_data(content_state, obj_classes_data) if caching? + end + + def fetch_search_result_from_cache(content_state, cache_index, cache_key) + content_state.find_obj_data(cache_index, cache_key) if caching? + end + + def request_search_result_from_backend(workspace, params) + CmsRestApi.get("workspaces/#{workspace.id}/objs/search", params) + end + + def store_search_result_in_cache(content_state, cache_index, cache_key, result) + content_state.save_obj_data(cache_index, cache_key, result) if caching? + 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)