SHARE
TWEET

Untitled

a guest May 19th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fileprivate func uploadAllContact(_ result: [String]) {
  2.        
  3. //        kylej
  4. //        if you are sending off ~600 phone numbers I would change things to send them all to the server at once in an array, in one request. then have the server insert them all in a .transaction {
  5. //        you will get much better performance.
  6. //
  7. //        as it is right now you are sending off ~600 different requests in a burst and the server is doing separate transactions for each. that could be your bottleneck - you'd need to measure to make sure (but it's still a good change to make regardless!)
  8.        
  9.         let phoneNumbers = self.phoneNumberKit.parse(result)
  10.        
  11.         UserDefaults.standard.setStructArray(phoneNumbers, forKey: "contacts")
  12.        
  13.         //let ownerID = PerfectLocalAuth.userid
  14.         guard let profileId = AppUserDefaults.value(forKey: .userProfileID, fallBackValue: "").string else {
  15.             return
  16.         }
  17.         _ = AppUserDefaults.save(value: phoneNumbers.count, forKey: .totalContactNumber)
  18.        
  19.         APIClient.findPhoneNumber(profileId: profileId).execute(onSuccess: { responsePhoneNumbers in
  20.            
  21.             let localContacts: [PhoneNumber?] = UserDefaults.standard.structArrayData(PhoneNumber.self, forKey: "contacts")
  22.             //let localContacts = AppUserDefaults.value(forKey: .contacts)
  23.            
  24.             // server contacts counte         local Contacts count
  25.             if responsePhoneNumbers.count != phoneNumbers.count {
  26.             // let fruitsArray = ["apple", "mango", "blueberry", "orange"]
  27.             // let vegArray = ["tomato", "potato", "mango", "blueberry"]
  28.             // var fruitsSet = Set(fruitsArray)
  29.             // let vegSet = Set(vegArray)
  30.             // let output = fruitsSet.subtracting(vegArray)
  31.             // print(output)
  32.                
  33.                 let localPhoneNumberArray = Set(localContacts.map{$0})
  34.                 let serverPhoneNumberArray = Set(responsePhoneNumbers.map{$0})
  35.                 let restOfContacts = localPhoneNumberArray.subtracting(serverPhoneNumberArray)
  36.  
  37.                 for num in restOfContacts {
  38.  
  39.                     DispatchQueue.main.async {
  40.  
  41.                         APIClient.createOrUpdatePhoneNumber(
  42.                             profileID: profileId,
  43.                             numberString: num!.numberString,
  44.                             countryCode: num!.countryCode,
  45.                             leadingZero: num!.leadingZero,
  46.                             nationalNumber: num!.nationalNumber,
  47.                             numberExtension: num?.numberExtension ?? "",
  48.                             type: num!.type.rawValue,
  49.                             regionID: num?.regionID ?? "",
  50.                             addame: false, ownerID: nil).execute(onSuccess: { numberCreate in
  51.                                 print(#line, "create or update contact number \(numberCreate)")
  52.                             }) { error in
  53.                                 print(#line, error.localizedDescription)
  54.                         }
  55.  
  56.                     }
  57.  
  58.                 }
  59.                
  60.             }
  61.            
  62.         }) { error in
  63.             log.error(#line, error.localizedDescription)
  64.         }
  65.  
  66.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top