Skip to content

Commit

Permalink
Build 8
Browse files Browse the repository at this point in the history
Signed-off-by: Marino Faggiana <[email protected]>
  • Loading branch information
marinofaggiana committed Dec 2, 2024
1 parent 729c962 commit fd91ece
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5474,7 +5474,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 7;
CURRENT_PROJECT_VERSION = 8;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -5540,7 +5540,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 7;
CURRENT_PROJECT_VERSION = 8;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down
25 changes: 3 additions & 22 deletions iOSClient/NCImageCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class NCImageCache: NSObject {
private let allowExtensions = [NCGlobal.shared.previewExt256]
private var brandElementColor: UIColor?

public var countLimit: Int = 0
public var countLimit: Int = 2000
lazy var cache: LRUCache<String, UIImage> = {
return LRUCache<String, UIImage>(countLimit: countLimit)
}()
Expand All @@ -47,22 +47,15 @@ class NCImageCache: NSObject {
override init() {
super.init()

countLimit = calculateMaxImages(percentage: 4, imageSizeKB: 30.0)
NextcloudKit.shared.nkCommonInstance.writeLog("Counter cache image: \(countLimit)")

NotificationCenter.default.addObserver(forName: LRUCacheMemoryWarningNotification, object: nil, queue: nil) { _ in
self.cache.removeAllValues()
self.cache = LRUCache<String, UIImage>(countLimit: self.countLimit)
#if DEBUG
NCContentPresenter().messageNotification("Cache image memory warning \(self.countLimit)", error: .success, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
#endif
}

NotificationCenter.default.addObserver(forName: UIApplication.didEnterBackgroundNotification, object: nil, queue: nil) { _ in
self.isDidEnterBackground = true
autoreleasepool {
self.cache.removeAllValues()
}
self.cache.removeAllValues()
self.cache = LRUCache<String, UIImage>(countLimit: self.countLimit)
}

NotificationCenter.default.addObserver(forName: UIApplication.willEnterForegroundNotification, object: nil, queue: nil) { _ in
Expand Down Expand Up @@ -99,9 +92,6 @@ class NCImageCache: NSObject {
self.cache.removeAllValues()
break
}
if metadata.isInvalidated {
continue
}
if let image = self.utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: NCGlobal.shared.previewExt256) {
self.addImageCache(ocId: metadata.ocId, etag: metadata.etag, image: image, ext: NCGlobal.shared.previewExt256, cost: cost)
cost += 1
Expand All @@ -128,15 +118,6 @@ class NCImageCache: NSObject {
NotificationCenter.default.removeObserver(self, name: LRUCacheMemoryWarningNotification, object: nil)
}

func calculateMaxImages(percentage: Double, imageSizeKB: Double) -> Int {
let totalRamBytes = Double(ProcessInfo.processInfo.physicalMemory)
let cacheSizeBytes = totalRamBytes * (percentage / 100.0)
let imageSizeBytes = imageSizeKB * 1024
let maxImages = Int(cacheSizeBytes / imageSizeBytes)

return maxImages
}

func allowExtensions(ext: String) -> Bool {
return allowExtensions.contains(ext)
}
Expand Down

0 comments on commit fd91ece

Please sign in to comment.