-
Notifications
You must be signed in to change notification settings - Fork 18
refactor: Simplify update upload file #2012
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
base: feature/upload-error-management
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -105,13 +105,9 @@ open class UploadFile( | |||||||
| fun uploadConflictOption() = if (replaceOnConflict()) ConflictOption.VERSION else ConflictOption.RENAME | ||||||||
|
|
||||||||
| fun resetUploadToken() { | ||||||||
| getRealmInstance().use { realm -> | ||||||||
| uploadFileByUriQuery(realm, uri).findFirst()?.apply { | ||||||||
| realm.executeTransaction { | ||||||||
| uploadToken = null | ||||||||
| uploadHost = null | ||||||||
| } | ||||||||
| } | ||||||||
| updateDbInstance { | ||||||||
| it.uploadToken = null | ||||||||
| it.uploadHost = null | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
|
|
@@ -127,24 +123,19 @@ open class UploadFile( | |||||||
| } | ||||||||
|
|
||||||||
| fun updateFileSize(newFileSize: Long) { | ||||||||
| getRealmInstance().use { realm -> | ||||||||
| uploadFileByUriQuery(realm, uri).findFirst()?.let { uploadFile -> | ||||||||
| realm.executeTransaction { uploadFile.fileSize = newFileSize } | ||||||||
| } | ||||||||
| update { | ||||||||
| it.fileSize = newFileSize | ||||||||
| } | ||||||||
| fileSize = newFileSize | ||||||||
| } | ||||||||
|
|
||||||||
| fun updateUploadToken(newUploadToken: String, uploadHost: String) { | ||||||||
| getRealmInstance().use { realm -> | ||||||||
| uploadFileByUriQuery(realm, uri).findFirst()?.let { uploadFile -> | ||||||||
| realm.executeTransaction { | ||||||||
| uploadFile.uploadToken = newUploadToken | ||||||||
| uploadFile.uploadHost = uploadHost | ||||||||
| } | ||||||||
| } | ||||||||
| updateDbInstance { | ||||||||
| it.uploadToken = newUploadToken | ||||||||
| it.uploadHost = uploadHost | ||||||||
| } | ||||||||
| updateCurrentInstance { | ||||||||
| it.uploadToken = newUploadToken | ||||||||
|
||||||||
| it.uploadToken = newUploadToken | |
| it.uploadToken = newUploadToken | |
| it.uploadHost = uploadHost |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, it appears that we don't update the host. I don't know if it's a bad thing or not or just an oversight
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resetUploadToken()now only updates the Realm row, leaving the in-memory instance’suploadToken/uploadHostpotentially stale. Call sites (e.g., retry/error paths) may continue using this sameUploadFileobject and re-cancel/retry with an already-reset token. Consider using the newupdate { ... }helper (or also callingupdateCurrentInstance) so both DB and current instance are reset consistently.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot it was already the case, which is goal of this PR to remove this bad hidden pattern and explicitly showing we update the DB only. And if we want to update the DB and the local instance (which I think we should), I'll change the code to use update method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
resetUploadToken()to useupdate { ... }in commit 90ebd45, so it now updates both the DB and the current in-memory instance consistently.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no I don't want any change I want a human review on it