From 3b691345d8270b9e076b08635efaa0294d25741e Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Tue, 17 Jan 2023 00:04:12 +0300 Subject: [PATCH] Optimizing performance of history list --- AutoCat.xcodeproj/project.pbxproj | 4 ++-- AutoCat/Utils/RxRealmDataSource.swift | 2 +- AutoCatCore/Models/Cloneable.swift | 5 +++++ AutoCatCore/Models/Vehicle.swift | 18 +++++++++++++++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index f8143cd..6feca92 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -1136,7 +1136,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 103; + CURRENT_PROJECT_VERSION = 104; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; @@ -1161,7 +1161,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 103; + CURRENT_PROJECT_VERSION = 104; DEVELOPMENT_TEAM = 46DTTB8X4S; INFOPLIST_FILE = AutoCat/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; diff --git a/AutoCat/Utils/RxRealmDataSource.swift b/AutoCat/Utils/RxRealmDataSource.swift index f93d895..5870100 100644 --- a/AutoCat/Utils/RxRealmDataSource.swift +++ b/AutoCat/Utils/RxRealmDataSource.swift @@ -89,7 +89,7 @@ class RealmSectionedDataSource: NSObject, UITableViewDataSource } func reload(animated: Bool = true) { - var items = self.data.toArray().map { $0.clone() } + var items = self.data.toArray().map { $0.shallowClone() } if let predicate = self.filterPredicate { items = items.filter(predicate) } diff --git a/AutoCatCore/Models/Cloneable.swift b/AutoCatCore/Models/Cloneable.swift index 6086a33..728ddb3 100644 --- a/AutoCatCore/Models/Cloneable.swift +++ b/AutoCatCore/Models/Cloneable.swift @@ -2,10 +2,15 @@ import Foundation public protocol Cloneable { init(copy: Self) + func shallowClone() -> Self } extension Cloneable { public func clone() -> Self { return Self.init(copy: self) } + + public func shallowClone() -> Self { + return clone() + } } diff --git a/AutoCatCore/Models/Vehicle.swift b/AutoCatCore/Models/Vehicle.swift index eb97629..a263f9b 100644 --- a/AutoCatCore/Models/Vehicle.swift +++ b/AutoCatCore/Models/Vehicle.swift @@ -160,7 +160,7 @@ public class VehicleOwnershipPeriod: Object, Decodable, Cloneable { } } -public class Vehicle: Object, Decodable, Identifiable, Differentiable, Cloneable, Exportable { +public final class Vehicle: Object, Decodable, Identifiable, Differentiable, Cloneable, Exportable { @objc public dynamic var brand: VehicleBrand? @objc public dynamic var model: VehicleModel? @objc public dynamic var color: String? @@ -361,6 +361,22 @@ public class Vehicle: Object, Decodable, Identifiable, Differentiable, Cloneable self.synchronized = copy.synchronized } + public func shallowClone() -> Vehicle { + let vehicle = Vehicle() + vehicle.number = self.number + vehicle.currentNumber = self.currentNumber + vehicle.addedDate = self.addedDate + vehicle.updatedDate = self.updatedDate + vehicle.brand = self.brand + vehicle.synchronized = self.synchronized + + let notes = List() + notes.append(objectsIn: self.notes.map { $0.clone() }) + vehicle.notes = notes + + return vehicle + } + // MARK: - Exportable public static var csvHeader: String {