Skip to content

Commit

Permalink
fix freezes (#3246)
Browse files Browse the repository at this point in the history
* #3184: Download Limit Support

- Added tableDownloadLimit entity to app database.
- Extended capability query to also consider download limit app.
- Extended capabilities list view for display of download limit availability.
- Extended share detail user interface to mimic the web user interface for managing download limits.
- Every time WebDAV properties of a file are retrieved, its associated download limits are removed and recreated.

Housekeeping:
- Outsourced NCShareDateCell into dedicated source code file.
- Outsourced NCShareToggleCell into dedicated source code file.

Notes:
- In my first attempt I had a detail view in the download limit row of the advanced share options showing the remaining number of downloads. However, that required to inject and retain the download limit entity object into the complicated share table configuration object. That, in turn, results in inconsistent data state due to invalid and outdated references. To resolve those issues, the assembly of the advanced share options user interface needs some refactoring which appears to expansive at this point and I prefer to leave it as it is for now.

Signed-off-by: Iva Horn <[email protected]>

* Updated NextcloudKit reference to files_downloadlimit branch.

Signed-off-by: Iva Horn <[email protected]>

* Update iOSClient/Data/NCManageDatabase+DownloadLimit.swift

Signed-off-by: Milen Pivchev <[email protected]>

* fix

Signed-off-by: Marino Faggiana <[email protected]>

* Updated NextcloudKit reference to develop branch.

Signed-off-by: Iva Horn <[email protected]>

* Fix(l10n): Update translations from Transifex

Signed-off-by: Nextcloud bot <[email protected]>

* Fix(l10n): Update translations from Transifex

Signed-off-by: Nextcloud bot <[email protected]>

* fix

Signed-off-by: Marino Faggiana <[email protected]>

---------

Signed-off-by: Iva Horn <[email protected]>
Signed-off-by: Milen Pivchev <[email protected]>
Signed-off-by: Marino Faggiana <[email protected]>
Signed-off-by: Nextcloud bot <[email protected]>
Co-authored-by: Iva Horn <[email protected]>
Co-authored-by: Milen Pivchev <[email protected]>
Co-authored-by: Nextcloud bot <[email protected]>
  • Loading branch information
4 people authored Dec 23, 2024
1 parent 4c76525 commit cd2e24b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5576,7 +5576,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 6.2.1;
MARKETING_VERSION = 6.2.2;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "-v";
OTHER_LDFLAGS = "";
Expand Down Expand Up @@ -5639,7 +5639,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 6.2.1;
MARKETING_VERSION = 6.2.2;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "-v";
OTHER_LDFLAGS = "";
Expand Down
22 changes: 14 additions & 8 deletions iOSClient/Files/NCFiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class NCFiles: NCCollectionViewCommon {
internal var fileNameBlink: String?
internal var fileNameOpen: String?
internal var matadatasHash: String = ""
internal var reloadDataSourceInProgress: Bool = false
internal var semaphoreReloadDataSource = DispatchSemaphore(value: 1)

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Expand Down Expand Up @@ -122,12 +122,16 @@ class NCFiles: NCCollectionViewCommon {
// MARK: - DataSource

override func reloadDataSource() {
guard !isSearchingMode,
!reloadDataSourceInProgress
guard !isSearchingMode
else {
return super.reloadDataSource()
}
reloadDataSourceInProgress = true

// This is only a fail safe "dead lock", I don't think the timeout will ever be called but at least nothing gets stuck, if after 5 sec. (which is a long time in this routine), the semaphore is still locked
//
if self.semaphoreReloadDataSource.wait(timeout: .now() + 5) == .timedOut {
self.semaphoreReloadDataSource.signal()
}

var predicate = self.defaultPredicate
let predicateDirectory = NSPredicate(format: "account == %@ AND serverUrl == %@", session.account, self.serverUrl)
Expand All @@ -145,14 +149,16 @@ class NCFiles: NCCollectionViewCommon {
self.dataSource = NCCollectionViewDataSource(metadatas: metadatas, layoutForView: layoutForView)

if metadatas.isEmpty {
reloadDataSourceInProgress = false
self.semaphoreReloadDataSource.signal()
return super.reloadDataSource()
}

self.dataSource.caching(metadatas: metadatas, dataSourceMetadatas: dataSourceMetadatas) { updated in
self.reloadDataSourceInProgress = false
if updated || self.isNumberOfItemsInAllSectionsNull || self.numberOfItemsInAllSections != metadatas.count {
super.reloadDataSource()
self.semaphoreReloadDataSource.signal()
DispatchQueue.main.async {
if updated || self.isNumberOfItemsInAllSectionsNull || self.numberOfItemsInAllSections != metadatas.count {
super.reloadDataSource()
}
}
}
}
Expand Down
19 changes: 17 additions & 2 deletions iOSClient/Media/NCMedia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class NCMedia: UIViewController {
@IBOutlet weak var menuButton: UIButton!
@IBOutlet weak var gradientView: UIView!

let semaphoreSearchMedia = DispatchSemaphore(value: 1)
let semaphoreNotificationCenter = DispatchSemaphore(value: 1)

let layout = NCMediaLayout()
var layoutType = NCGlobal.shared.mediaLayoutRatio
var documentPickerViewController: NCDocumentPickerViewController?
Expand Down Expand Up @@ -257,13 +260,25 @@ class NCMedia: UIViewController {
return
}

// This is only a fail safe "dead lock", I don't think the timeout will ever be called but at least nothing gets stuck, if after 5 sec. (which is a long time in this routine), the semaphore is still locked
//
if self.semaphoreNotificationCenter.wait(timeout: .now() + 5) == .timedOut {
self.semaphoreNotificationCenter.signal()
}

if error.errorCode == self.global.errorResourceNotFound,
let ocId = userInfo["ocId"] as? String {
self.database.deleteMetadataOcId(ocId)
self.loadDataSource()
self.loadDataSource {
self.semaphoreNotificationCenter.signal()
}
} else if error != .success {
NCContentPresenter().showError(error: error)
self.loadDataSource()
self.loadDataSource {
self.semaphoreNotificationCenter.signal()
}
} else {
semaphoreNotificationCenter.signal()
}
}

Expand Down
7 changes: 5 additions & 2 deletions iOSClient/Media/NCMediaDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ extension NCMedia {
NCNetworking.shared.downloadThumbnailQueue.operationCount == 0,
let tableAccount = database.getTableAccount(predicate: NSPredicate(format: "account == %@", session.account))
else { return }
self.searchMediaInProgress = true

let limit = max(self.collectionView.visibleCells.count * 3, 300)
let visibleCells = self.collectionView?.indexPathsForVisibleItems.sorted(by: { $0.row < $1.row }).compactMap({ self.collectionView?.cellForItem(at: $0) })

DispatchQueue.global(qos: .background).async {
self.semaphoreSearchMedia.wait()
self.searchMediaInProgress = true

var lessDate = Date.distantFuture
var greaterDate = Date.distantPast
let countMetadatas = self.dataSource.metadatas.count
Expand Down Expand Up @@ -156,6 +157,8 @@ extension NCMedia {
self.collectionViewReloadData()
}

self.semaphoreSearchMedia.signal()

DispatchQueue.main.async {
self.activityIndicator.stopAnimating()
self.searchMediaInProgress = false
Expand Down

0 comments on commit cd2e24b

Please sign in to comment.