IOS-1495 uses one queue per list insstead of one queue per list item IOS-1521+IOS-1495
authorbuff <andreas@pep-project.org>
Tue, 14 May 2019 19:07:45 +0200
branchIOS-1521+IOS-1495
changeset 8613463170dfc0b8
parent 8612 961366028e40
child 8614 9332d31f8949
IOS-1495 uses one queue per list insstead of one queue per list item
pEpForiOS/UI/EmailDisplayList/EmailListViewCell.swift
pEpForiOS/UI/EmailDisplayList/EmailListViewModel.swift
pEpForiOS/UI/EmailDisplayList/MessageViewModel.swift
     1.1 --- a/pEpForiOS/UI/EmailDisplayList/EmailListViewCell.swift	Tue May 14 18:30:47 2019 +0200
     1.2 +++ b/pEpForiOS/UI/EmailDisplayList/EmailListViewCell.swift	Tue May 14 19:07:45 2019 +0200
     1.3 @@ -178,6 +178,8 @@
     1.4      }
     1.5  
     1.6      private func resetToDefault() {
     1.7 +        viewModel?.unsubscribeForUpdates()
     1.8 +        viewModel = nil
     1.9          summaryLabel.text = nil
    1.10          ratingImage.isHidden = true
    1.11          contactImageView.image = EmailListViewCell.emptyContactImage
     2.1 --- a/pEpForiOS/UI/EmailDisplayList/EmailListViewModel.swift	Tue May 14 18:30:47 2019 +0200
     2.2 +++ b/pEpForiOS/UI/EmailDisplayList/EmailListViewModel.swift	Tue May 14 19:07:45 2019 +0200
     2.3 @@ -42,10 +42,10 @@
     2.4  
     2.5      var indexPathShown: IndexPath?
     2.6  
     2.7 -    private let queue: OperationQueue = {
     2.8 +    private let queueForHeavyStuff: OperationQueue = {
     2.9          let createe = OperationQueue()
    2.10          createe.qualityOfService = .userInitiated
    2.11 -        createe.maxConcurrentOperationCount = 1
    2.12 +        createe.name = "security.pep.EmailListViewModel.queueForHeavyStuff"
    2.13          return createe
    2.14      }()
    2.15  
    2.16 @@ -101,9 +101,8 @@
    2.17  
    2.18      private var selectedItems: Set<IndexPath>?
    2.19  
    2.20 -    weak var updateThreadListDelegate: UpdateThreadListDelegate? //!!!: sounds like belonging to message thread. If so, comment out
    2.21 -
    2.22      // Threading feature is currently non-existing. Keep this code, might help later.
    2.23 +//    weak var updateThreadListDelegate: UpdateThreadListDelegate?
    2.24  //    var oldThreadSetting : Bool
    2.25  
    2.26      // MARK: - Life Cycle
    2.27 @@ -161,7 +160,8 @@
    2.28      }
    2.29  
    2.30      func viewModel(for index: Int) -> MessageViewModel? {
    2.31 -        let messageViewModel = MessageViewModel(with: messageQueryResults[index])
    2.32 +        let messageViewModel = MessageViewModel(with: messageQueryResults[index],
    2.33 +                                                queue: queueForHeavyStuff)
    2.34          return messageViewModel
    2.35      }
    2.36  
     3.1 --- a/pEpForiOS/UI/EmailDisplayList/MessageViewModel.swift	Tue May 14 18:30:47 2019 +0200
     3.2 +++ b/pEpForiOS/UI/EmailDisplayList/MessageViewModel.swift	Tue May 14 19:07:45 2019 +0200
     3.3 @@ -13,9 +13,10 @@
     3.4  import PEPObjCAdapterFramework
     3.5  
     3.6  class MessageViewModel: CustomDebugStringConvertible {
     3.7 +    static fileprivate var maxBodyPreviewCharacters = 120
     3.8  
     3.9 -    static var maxBodyPreviewCharacters = 120
    3.10 -    var queue: OperationQueue
    3.11 +    private var queue: OperationQueue
    3.12 +    private var runningOperations = [Operation]()
    3.13  
    3.14      let uid: Int
    3.15      private let uuid: MessageID
    3.16 @@ -58,12 +59,10 @@
    3.17      //Only to use internally, external use should call public message()
    3.18      private var internalMessage: Message
    3.19  
    3.20 -    init(with message: Message, operationQueue: OperationQueue = OperationQueue()) {
    3.21 +    required init(with message: Message, queue: OperationQueue) {
    3.22          internalMessage = message
    3.23  
    3.24 -        queue = operationQueue
    3.25 -        queue.qualityOfService = .userInitiated
    3.26 -        queue.maxConcurrentOperationCount = 3
    3.27 +        self.queue = queue
    3.28  
    3.29          uid = message.uid
    3.30          uuid = message.uuid
    3.31 @@ -109,11 +108,11 @@
    3.32      }
    3.33  
    3.34      func unsubscribeForUpdates() {
    3.35 -        cancelLoad()
    3.36 +        cancelAllBackgroundOperations()
    3.37      }
    3.38  
    3.39 -    private func cancelLoad() {
    3.40 -        queue.cancelAllOperations()
    3.41 +    private func cancelAllBackgroundOperations() {
    3.42 +        runningOperations.forEach { $0.cancel() }
    3.43      }
    3.44  
    3.45      private func setBodyPeek(for message:Message) {
    3.46 @@ -124,7 +123,7 @@
    3.47                  self.bodyPeek = bodyPeek
    3.48              }
    3.49              if(!operation.isFinished){
    3.50 -                queue.addOperation(operation)
    3.51 +                addToRunningOperations(operation)
    3.52              }
    3.53          }
    3.54      }
    3.55 @@ -147,7 +146,7 @@
    3.56  //                completion(count)
    3.57  //            }
    3.58  //            if(!operation.isFinished){
    3.59 -//                queue.addOperation(operation)
    3.60 +//                addToRunningOperations(operation)
    3.61  //            }
    3.62  //        }
    3.63  //    }
    3.64 @@ -246,12 +245,12 @@
    3.65  
    3.66      func getProfilePicture(completion: @escaping (UIImage?) -> ()) {
    3.67          let operation = getProfilePictureOperation(completion: completion)
    3.68 -        queue.addOperation(operation)
    3.69 +        addToRunningOperations(operation)
    3.70      }
    3.71  
    3.72      func getSecurityBadge(completion: @escaping (UIImage?) ->()) {
    3.73          let operation = getSecurityBadgeOperation(completion: completion)
    3.74 -        queue.addOperation(operation)
    3.75 +        addToRunningOperations(operation)
    3.76      }
    3.77  
    3.78      func getBodyMessage() -> NSMutableAttributedString {
    3.79 @@ -330,6 +329,11 @@
    3.80  
    3.81  extension MessageViewModel {
    3.82  
    3.83 +    private func addToRunningOperations(_ op: Operation) {
    3.84 +        runningOperations.append(op)
    3.85 +        queue.addOperation(op)
    3.86 +    }
    3.87 +
    3.88      private func getBodyPeekOperation(for message: Message, completion: @escaping (String)->()) -> SelfReferencingOperation {
    3.89  
    3.90          let getBodyPeekOperation = SelfReferencingOperation {operation in