Skip to content

Commit

Permalink
Parallelise conversion of NKFiles to NextcloudItemMetadataTables
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 b4d8290
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,31 @@ extension NextcloudItemMetadataTable {
var childDirectoriesMetadatas: [NextcloudItemMetadataTable] = []
var metadatas: [NextcloudItemMetadataTable] = []

for file in files {
let metadata = NextcloudItemMetadataTable.fromNKFile(file, account: account)
let conversionQueue = DispatchQueue(label: "nkFileToMetadataConversionQueue", qos: .userInitiated, attributes: .concurrent)
let appendQueue = DispatchQueue(label: "metadataAppendQueue", qos: .userInitiated) // Serial queue
let dispatchGroup = DispatchGroup()

for file in files {
if metadatas.isEmpty && !directoryMetadataSet {
assert(metadata.directory) // In directory read first metadata will always be a dir
let metadata = NextcloudItemMetadataTable.fromNKFile(file, account: account)
directoryMetadata = metadata;
directoryMetadataSet = true;
} else {
metadatas.append(metadata)
if metadata.directory {
childDirectoriesMetadatas.append(metadata)
conversionQueue.async(group: dispatchGroup) {
let metadata = NextcloudItemMetadataTable.fromNKFile(file, account: account)

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 b4d8290

Please sign in to comment.