Skip to content

Commit

Permalink
Parallelise conversion of NKFiles to NextclkoudItemMetadataTables
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Mar 20, 2023
1 parent 265d386 commit 063754f
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,30 @@ extension NextcloudItemMetadataTable {
var childDirectoriesMetadatas: [NextcloudItemMetadataTable] = []
var metadatas: [NextcloudItemMetadataTable] = []

let conversionQueue = DispatchQueue(label: "nkFileToMetadataConversionQueue", qos: .userInitiated, attributes: .concurrent)
let appendQueue = DispatchQueue(label: "metadataAppendQueue", qos: .userInitiated)
let dispatchGroup = DispatchGroup()

for file in files {
let metadata = NextcloudItemMetadataTable.fromNKFile(file, account: account)
conversionQueue.async(group: dispatchGroup) {
let metadata = NextcloudItemMetadataTable.fromNKFile(file, account: account)

if metadatas.isEmpty && !directoryMetadataSet {
assert(metadata.directory) // In directory read first metadata will always be a dir
directoryMetadata = metadata;
directoryMetadataSet = true;
} else {
metadatas.append(metadata)
if metadata.directory {
childDirectoriesMetadatas.append(metadata)
if metadatas.isEmpty && !directoryMetadataSet {
directoryMetadata = metadata;
directoryMetadataSet = true;
} else {
appendQueue.async(group: dispatchGroup) {
metadatas.append(metadata)
if metadata.directory {
childDirectoriesMetadatas.append(metadata)
}
}
}
}
}

completionHandler(directoryMetadata, childDirectoriesMetadatas, metadatas)
dispatchGroup.notify(queue: DispatchQueue.main) {
completionHandler(directoryMetadata, childDirectoriesMetadatas, metadatas)
}
}
}

0 comments on commit 063754f

Please sign in to comment.