Cllean up function and method calls in File Provider Extension

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-02-05 17:31:55 +08:00 committed by Matthieu Gallien
parent d707ccc5b3
commit 7ac5f38178
6 changed files with 46 additions and 21 deletions

View file

@ -28,8 +28,10 @@ extension NextcloudFilesDatabaseManager {
of: placeholderSeparator, with: problematicSeparator) of: placeholderSeparator, with: problematicSeparator)
if let metadata = ncDatabase().objects(NextcloudItemMetadataTable.self).filter( if let metadata = ncDatabase().objects(NextcloudItemMetadataTable.self).filter(
"account == %@ AND serverUrl == %@ AND fileName == %@ AND directory == true", account, "account == %@ AND serverUrl == %@ AND fileName == %@ AND directory == true",
directoryItemServerUrl, directoryItemFileName account,
directoryItemServerUrl,
directoryItemFileName
).first { ).first {
return NextcloudItemMetadataTable(value: metadata) return NextcloudItemMetadataTable(value: metadata)
} }

View file

@ -123,7 +123,9 @@ class NextcloudFilesDatabaseManager: NSObject {
-> [NextcloudItemMetadataTable] -> [NextcloudItemMetadataTable]
{ {
let metadatas = ncDatabase().objects(NextcloudItemMetadataTable.self).filter( let metadatas = ncDatabase().objects(NextcloudItemMetadataTable.self).filter(
"account == %@ AND serverUrl == %@ AND status == %@", account, serverUrl, "account == %@ AND serverUrl == %@ AND status == %@",
account,
serverUrl,
status.rawValue) status.rawValue)
return sortedItemMetadatas(metadatas) return sortedItemMetadatas(metadatas)
} }
@ -216,7 +218,9 @@ class NextcloudFilesDatabaseManager: NSObject {
} }
func updateItemMetadatas( func updateItemMetadatas(
account: String, serverUrl: String, updatedMetadatas: [NextcloudItemMetadataTable], account: String,
serverUrl: String,
updatedMetadatas: [NextcloudItemMetadataTable],
updateDirectoryEtags: Bool updateDirectoryEtags: Bool
) -> ( ) -> (
newMetadatas: [NextcloudItemMetadataTable]?, newMetadatas: [NextcloudItemMetadataTable]?,
@ -227,7 +231,9 @@ class NextcloudFilesDatabaseManager: NSObject {
do { do {
let existingMetadatas = database.objects(NextcloudItemMetadataTable.self).filter( let existingMetadatas = database.objects(NextcloudItemMetadataTable.self).filter(
"account == %@ AND serverUrl == %@ AND status == %@", account, serverUrl, "account == %@ AND serverUrl == %@ AND status == %@",
account,
serverUrl,
NextcloudItemMetadataTable.Status.normal.rawValue) NextcloudItemMetadataTable.Status.normal.rawValue)
let metadatasToDelete = processItemMetadatasToDelete( let metadatasToDelete = processItemMetadatasToDelete(
@ -249,7 +255,8 @@ class NextcloudFilesDatabaseManager: NSObject {
for metadata in directoriesNeedingRename { for metadata in directoriesNeedingRename {
if let updatedDirectoryChildren = renameDirectoryAndPropagateToChildren( if let updatedDirectoryChildren = renameDirectoryAndPropagateToChildren(
ocId: metadata.ocId, newServerUrl: metadata.serverUrl, ocId: metadata.ocId,
newServerUrl: metadata.serverUrl,
newFileName: metadata.fileName) newFileName: metadata.fileName)
{ {
metadatasToUpdate += updatedDirectoryChildren metadatasToUpdate += updatedDirectoryChildren
@ -270,7 +277,8 @@ class NextcloudFilesDatabaseManager: NSObject {
} }
return ( return (
newMetadatas: metadatasToCreate, updatedMetadatas: metadatasToUpdate, newMetadatas: metadatasToCreate,
updatedMetadatas: metadatasToUpdate,
deletedMetadatas: metadatasToDelete deletedMetadatas: metadatasToDelete
) )
} catch { } catch {
@ -282,7 +290,8 @@ class NextcloudFilesDatabaseManager: NSObject {
} }
func setStatusForItemMetadata( func setStatusForItemMetadata(
_ metadata: NextcloudItemMetadataTable, status: NextcloudItemMetadataTable.Status, _ metadata: NextcloudItemMetadataTable,
status: NextcloudItemMetadataTable.Status,
completionHandler: @escaping (_ updatedMetadata: NextcloudItemMetadataTable?) -> Void completionHandler: @escaping (_ updatedMetadata: NextcloudItemMetadataTable?) -> Void
) { ) {
let database = ncDatabase() let database = ncDatabase()

View file

@ -104,8 +104,11 @@ extension NextcloudItemMetadataTable {
var metadatas: [NextcloudItemMetadataTable] = [] var metadatas: [NextcloudItemMetadataTable] = []
let conversionQueue = DispatchQueue( let conversionQueue = DispatchQueue(
label: "nkFileToMetadataConversionQueue", qos: .userInitiated, attributes: .concurrent) label: "nkFileToMetadataConversionQueue",
let appendQueue = DispatchQueue(label: "metadataAppendQueue", qos: .userInitiated) // Serial queue qos: .userInitiated,
attributes: .concurrent)
// appendQueue is a serial queue, not concurrent
let appendQueue = DispatchQueue(label: "metadataAppendQueue", qos: .userInitiated)
let dispatchGroup = DispatchGroup() let dispatchGroup = DispatchGroup()
for file in files { for file in files {

View file

@ -94,7 +94,8 @@ class NextcloudItemMetadataTable: Object {
@Persisted var sessionSelector = "" @Persisted var sessionSelector = ""
@Persisted var sessionTaskIdentifier: Int = 0 @Persisted var sessionTaskIdentifier: Int = 0
@Persisted var sharePermissionsCollaborationServices: Int = 0 @Persisted var sharePermissionsCollaborationServices: Int = 0
let sharePermissionsCloudMesh = List<String>() // TODO: Find a way to compare these in remote state check // TODO: Find a way to compare these two below in remote state check
let sharePermissionsCloudMesh = List<String>()
let shareType = List<Int>() let shareType = List<Int>()
@Persisted var size: Int64 = 0 @Persisted var size: Int64 = 0
@Persisted var status: Int = 0 @Persisted var status: Int = 0
@ -183,9 +184,12 @@ class NextcloudItemMetadataTable: Object {
func isInSameDatabaseStoreableRemoteState(_ comparingMetadata: NextcloudItemMetadataTable) func isInSameDatabaseStoreableRemoteState(_ comparingMetadata: NextcloudItemMetadataTable)
-> Bool -> Bool
{ {
comparingMetadata.etag == etag && comparingMetadata.fileNameView == fileNameView comparingMetadata.etag == etag
&& comparingMetadata.date == date && comparingMetadata.permissions == permissions && comparingMetadata.fileNameView == fileNameView
&& comparingMetadata.hasPreview == hasPreview && comparingMetadata.note == note && comparingMetadata.date == date
&& comparingMetadata.permissions == permissions
&& comparingMetadata.hasPreview == hasPreview
&& comparingMetadata.note == note
&& comparingMetadata.lock == lock && comparingMetadata.lock == lock
&& comparingMetadata.sharePermissionsCollaborationServices && comparingMetadata.sharePermissionsCollaborationServices
== sharePermissionsCollaborationServices == sharePermissionsCollaborationServices
@ -203,13 +207,13 @@ class NextcloudItemMetadataTable: Object {
} }
let urlBase = urlBase.urlEncoded! let urlBase = urlBase.urlEncoded!
let webdavUrl = urlBase + NextcloudAccount.webDavFilesUrlSuffix + user // Leave the leading slash // Leave the leading slash in webdavUrl
let webdavUrl = urlBase + NextcloudAccount.webDavFilesUrlSuffix + user
let serverFileRelativeUrl = let serverFileRelativeUrl =
serverUrl.replacingOccurrences(of: webdavUrl, with: "") + "/" + fileName serverUrl.replacingOccurrences(of: webdavUrl, with: "") + "/" + fileName
let urlString = let urlString =
"\(urlBase)/index.php/core/preview.png?file=\(serverFileRelativeUrl)&x=\(size.width)&y=\(size.height)&a=1&mode=cover" "\(urlBase)/index.php/core/preview.png?file=\(serverFileRelativeUrl)&x=\(size.width)&y=\(size.height)&a=1&mode=cover"
return URL(string: urlString) return URL(string: urlString)
} }
} }

View file

@ -23,7 +23,8 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
FileProviderEnumerator.isSystemIdentifier(enumeratedItemIdentifier) FileProviderEnumerator.isSystemIdentifier(enumeratedItemIdentifier)
} }
private let anchor = NSFileProviderSyncAnchor(Date().description.data(using: .utf8)!) // TODO: actually use this in NCKit and server requests // TODO: actually use this in NCKit and server requests
private let anchor = NSFileProviderSyncAnchor(Date().description.data(using: .utf8)!)
private static let maxItemsPerFileProviderPage = 100 private static let maxItemsPerFileProviderPage = 100
let ncAccount: NextcloudAccount let ncAccount: NextcloudAccount
let ncKit: NextcloudKit let ncKit: NextcloudKit
@ -35,7 +36,8 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
} }
init( init(
enumeratedItemIdentifier: NSFileProviderItemIdentifier, ncAccount: NextcloudAccount, enumeratedItemIdentifier: NSFileProviderItemIdentifier,
ncAccount: NextcloudAccount,
ncKit: NextcloudKit ncKit: NextcloudKit
) { ) {
self.enumeratedItemIdentifier = enumeratedItemIdentifier self.enumeratedItemIdentifier = enumeratedItemIdentifier
@ -317,8 +319,12 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
) )
FileProviderEnumerator.completeChangesObserver( FileProviderEnumerator.completeChangesObserver(
observer, anchor: anchor, ncKit: self.ncKit, newMetadatas: newMetadatas, observer,
updatedMetadatas: updatedMetadatas, deletedMetadatas: deletedMetadatas) anchor: anchor,
ncKit: self.ncKit,
newMetadatas: newMetadatas,
updatedMetadatas: updatedMetadatas,
deletedMetadatas: deletedMetadatas)
} }
} }

View file

@ -134,7 +134,8 @@ class FileProviderItem: NSObject, NSFileProviderItem {
} }
required init( required init(
metadata: NextcloudItemMetadataTable, parentItemIdentifier: NSFileProviderItemIdentifier, metadata: NextcloudItemMetadataTable,
parentItemIdentifier: NSFileProviderItemIdentifier,
ncKit: NextcloudKit ncKit: NextcloudKit
) { ) {
self.metadata = metadata self.metadata = metadata