Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent refetching PHAsset #1093

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kDriveCore/Data/Cache/DriveFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class DriveFileManager {
/// Something to centralize schema versioning
enum RealmSchemaVersion {
/// Current version of the Upload Realm
static let upload: UInt64 = 17
static let upload: UInt64 = 18

/// Current version of the Drive Realm
static let drive: UInt64 = 9
Expand Down
7 changes: 1 addition & 6 deletions kDriveCore/Data/Models/Upload/UploadingSessionTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,19 @@ public final class UploadingSessionTask: EmbeddedObject {
@Persisted public var sessionExpiration: Date
@Persisted public var chunkTasks: List<UploadingChunkTask>

/// The source file path
@Persisted public var filePath: String

override public init() {
// Required by Realm
super.init()
}

public convenience init(uploadSession: UploadSession,
sessionExpiration: Date,
chunkTasks: List<UploadingChunkTask>,
filePath: String) {
chunkTasks: List<UploadingChunkTask>) {
self.init()

self.uploadSession = uploadSession
self.sessionExpiration = sessionExpiration
self.chunkTasks = chunkTasks
self.filePath = filePath
}

// MARK: - Computed Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ extension UploadOperation {
return
}

// Check if we are not restarting a session for an already imported asset
if let existingFileURL = file.pathURL,
fileManager.fileExists(atPath: existingFileURL.path) {
return
}

// Async load the url of the asset
guard let url = await photoLibraryUploader.getUrl(for: asset) else {
Log.uploadOperation("Failed to get photo asset URL ufid:\(uploadFileId)", level: .error)
Expand All @@ -48,7 +54,6 @@ extension UploadOperation {
Log.uploadOperation("Got photo asset, writing URL:\(url) ufid:\(uploadFileId)")
try transactionWithFile { file in
file.pathURL = url
file.uploadingSession?.filePath = url.path
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension UploadOperation {
throw ErrorDomain.uploadSessionTaskMissing
}

filePath = uploadingSessionTask.filePath
filePath = file.pathURL?.path ?? ""
let sessionToken = uploadingSessionTask.token

// Look for the next chunk to generate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,6 @@ extension UploadOperation {
// Store the session token asap as a non null ivar
uploadingSessionTask.token = session.token

// The file at the moment we created the UploadingSessionTask
uploadingSessionTask.filePath = fileUrl.path

// Store the session
uploadingSessionTask.uploadSession = session

Expand Down
Loading