Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Removed FileIdQuery and optimized FileLinkSyncService

Andreas Pfohl4bcfdecb0d05
diff --git a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_id_query.rb b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_id_query.rb
deleted file mode 100644
index 3111f65141d..00000000000
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/file_id_query.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2023 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-module Storages::Peripherals::StorageInteraction::Nextcloud
- class FileIdQuery
- def initialize(storage)
- @query = ::Storages::Peripherals::StorageInteraction::Nextcloud::Internal::PropfindQuery.new(storage)
- end
-
- def call(path:)
- query_params = {
- depth: '0',
- path:,
- props: %w[oc:fileid]
- }
-
- @query.call(**query_params).map { |result| result.dig(path, 'fileid') }
- end
- end
-end
diff --git a/modules/storages/app/common/storages/peripherals/storage_requests.rb b/modules/storages/app/common/storages/peripherals/storage_requests.rb
index f60402fc6c5..b74095526de 100644
--- a/modules/storages/app/common/storages/peripherals/storage_requests.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_requests.rb
@@ -42,7 +42,6 @@ module Storages::Peripherals
download_link_query
files_info_query
files_query
- file_id_query
file_ids_query
upload_link_query
group_users_query
diff --git a/modules/storages/app/services/projects/copy/storage_project_folders_dependent_service.rb b/modules/storages/app/services/projects/copy/storage_project_folders_dependent_service.rb
index aeeca57f37c..72cb355d348 100644
--- a/modules/storages/app/services/projects/copy/storage_project_folders_dependent_service.rb
+++ b/modules/storages/app/services/projects/copy/storage_project_folders_dependent_service.rb
@@ -71,10 +71,10 @@ module Projects::Copy
Storages::Peripherals::StorageRequests
.new(storage: project_storage.storage)
- .file_id_query
+ .file_ids_query
.call(path: destination_folder_name)
.match(
- on_success: ->(file_id) { project_storage.update!(project_folder_id: file_id) },
+ on_success: ->(file_ids) { project_storage.update!(project_folder_id: file_ids.first) },
on_failure: ->(error) { add_error!(destination_folder_name, error.to_active_model_errors) }
)
end
diff --git a/modules/storages/app/services/storages/file_link_sync_service.rb b/modules/storages/app/services/storages/file_link_sync_service.rb
index a043cad7b9b..8c484fb84d2 100644
--- a/modules/storages/app/services/storages/file_link_sync_service.rb
+++ b/modules/storages/app/services/storages/file_link_sync_service.rb
@@ -34,17 +34,17 @@ class Storages::FileLinkSyncService
end
def call(file_links)
- file_links
+ resulting_file_links = file_links
.group_by(&:storage_id)
.map { |storage_id, storage_file_links| sync_nextcloud(storage_id, storage_file_links) }
- .reduce(ServiceResult.success(result: [])) do |state, sync_result|
- state >> ->(state_result) do
+ .reduce([]) do |state, sync_result|
sync_result.match(
- on_success: ->(sr) { ServiceResult.success(result: state_result + sr) },
- on_failure: ->(_) { ServiceResult.success(result: state_result) }
+ on_success: ->(sr) { state + sr },
+ on_failure: ->(_) { state }
)
end
- end
+
+ ServiceResult.success(result: resulting_file_links)
end
private
@@ -54,7 +54,7 @@ class Storages::FileLinkSyncService
.new(storage: ::Storages::Storage.find(storage_id))
.files_info_query
.call(user: @user, file_ids: file_links.map(&:origin_id))
- .map(&to_hash)
+ .map { |file_infos| to_hash(file_infos) }
.match(
on_success: set_file_link_permissions(file_links),
on_failure: ->(_) {
@@ -66,8 +66,8 @@ class Storages::FileLinkSyncService
)
end
- def to_hash
- ->(file_infos) { file_infos.index_by { |file_info| file_info.id.to_s }.to_h }
+ def to_hash(file_infos)
+ file_infos.index_by { |file_info| file_info.id.to_s }.to_h
end
def set_file_link_permissions(file_links)
diff --git a/modules/storages/app/services/storages/group_folder_properties_sync_service.rb b/modules/storages/app/services/storages/group_folder_properties_sync_service.rb
index 5f4dd4c7abe..a6c5182052d 100644
--- a/modules/storages/app/services/storages/group_folder_properties_sync_service.rb
+++ b/modules/storages/app/services/storages/group_folder_properties_sync_service.rb
@@ -147,10 +147,10 @@ class Storages::GroupFolderPropertiesSyncService
def obtain_file_id
->((project_storage, path)) do
@requests
- .file_id_query
+ .files_id_query
.call(path:)
.match(
- on_success: ->(file_id) { ServiceResult.success(result: [project_storage, file_id]) },
+ on_success: ->(file_ids) { ServiceResult.success(result: [project_storage, file_ids.first]) },
on_failure: failure_handler('file_id_query', { path: })
)
end