Optimizing performance of history list

This commit is contained in:
Selim Mustafaev 2023-01-17 00:04:12 +03:00
parent f4b5b7d328
commit 3b691345d8
4 changed files with 25 additions and 4 deletions

View File

@ -1136,7 +1136,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 103; CURRENT_PROJECT_VERSION = 104;
DEVELOPMENT_TEAM = 46DTTB8X4S; DEVELOPMENT_TEAM = 46DTTB8X4S;
INFOPLIST_FILE = AutoCat/Info.plist; INFOPLIST_FILE = AutoCat/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0; IPHONEOS_DEPLOYMENT_TARGET = 13.0;
@ -1161,7 +1161,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements; CODE_SIGN_ENTITLEMENTS = AutoCat/AutoCat.entitlements;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 103; CURRENT_PROJECT_VERSION = 104;
DEVELOPMENT_TEAM = 46DTTB8X4S; DEVELOPMENT_TEAM = 46DTTB8X4S;
INFOPLIST_FILE = AutoCat/Info.plist; INFOPLIST_FILE = AutoCat/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0; IPHONEOS_DEPLOYMENT_TARGET = 13.0;

View File

@ -89,7 +89,7 @@ class RealmSectionedDataSource<Item,Cell>: NSObject, UITableViewDataSource
} }
func reload(animated: Bool = true) { 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 { if let predicate = self.filterPredicate {
items = items.filter(predicate) items = items.filter(predicate)
} }

View File

@ -2,10 +2,15 @@ import Foundation
public protocol Cloneable { public protocol Cloneable {
init(copy: Self) init(copy: Self)
func shallowClone() -> Self
} }
extension Cloneable { extension Cloneable {
public func clone() -> Self { public func clone() -> Self {
return Self.init(copy: self) return Self.init(copy: self)
} }
public func shallowClone() -> Self {
return clone()
}
} }

View File

@ -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 brand: VehicleBrand?
@objc public dynamic var model: VehicleModel? @objc public dynamic var model: VehicleModel?
@objc public dynamic var color: String? @objc public dynamic var color: String?
@ -361,6 +361,22 @@ public class Vehicle: Object, Decodable, Identifiable, Differentiable, Cloneable
self.synchronized = copy.synchronized 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<VehicleNote>()
notes.append(objectsIn: self.notes.map { $0.clone() })
vehicle.notes = notes
return vehicle
}
// MARK: - Exportable // MARK: - Exportable
public static var csvHeader: String { public static var csvHeader: String {