From 4ea1d9ca99edeba6a5ab144d4bfc346468b1eff9 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Mon, 9 Mar 2020 18:40:25 +0000 Subject: [PATCH 1/4] refactor: remove KeyPath dependency on Attribute --- Sources/QueryKit/KeyPath.swift | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/Sources/QueryKit/KeyPath.swift b/Sources/QueryKit/KeyPath.swift index f55733d..8991eaa 100644 --- a/Sources/QueryKit/KeyPath.swift +++ b/Sources/QueryKit/KeyPath.swift @@ -1,5 +1,9 @@ import CoreData +func expression(for keyPath: KeyPath) -> NSExpression { + return NSExpression(forKeyPath: (keyPath as AnyKeyPath)._kvcKeyPathString!) +} + // MARK: Predicate public func == (lhs: KeyPath, rhs: V) -> Predicate { @@ -41,46 +45,37 @@ public func << (lhs: KeyPath, rhs: Range) -> Pr // MARK: - NSPredicate public func == (lhs: KeyPath, rhs: V) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute == rhs + return expression(for: lhs) == NSExpression(forConstantValue: rhs) } public func != (lhs: KeyPath, rhs: V) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute != rhs + return expression(for: lhs) != NSExpression(forConstantValue: rhs) } public func > (lhs: KeyPath, rhs: V) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute > rhs + return expression(for: lhs) > NSExpression(forConstantValue: rhs) } public func >= (lhs: KeyPath, rhs: V) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute >= rhs + return expression(for: lhs) >= NSExpression(forConstantValue: rhs) } public func < (lhs: KeyPath, rhs: V) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute < rhs + return expression(for: lhs) < NSExpression(forConstantValue: rhs) } public func <= (lhs: KeyPath, rhs: V) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute <= rhs + return expression(for: lhs) <= NSExpression(forConstantValue: rhs) } public func ~= (lhs: KeyPath, rhs: V) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute ~= rhs + return expression(for: lhs) ~= NSExpression(forConstantValue: rhs) } public func << (lhs: KeyPath, rhs: [V]) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute << rhs + return expression(for: lhs) << NSExpression(forConstantValue: rhs) } public func << (lhs: KeyPath, rhs: Range) -> NSPredicate { - let attribute = Attribute((lhs as AnyKeyPath)._kvcKeyPathString!) - return attribute << rhs + return expression(for: lhs) << NSExpression(forConstantValue: rhs) } From 9407c92c0089c45a085ac7b112e07b9ef511dc25 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Mon, 9 Mar 2020 18:40:33 +0000 Subject: [PATCH 2/4] release: 0.14.1 --- CHANGELOG.md | 2 +- QueryKit.podspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7614781..8001372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # QueryKit Changelog -## Master +## 0.14.1 ### Bug Fixes diff --git a/QueryKit.podspec b/QueryKit.podspec index 9111f55..03c48fd 100644 --- a/QueryKit.podspec +++ b/QueryKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'QueryKit' - spec.version = '0.14.0' + spec.version = '0.14.1' spec.summary = 'A simple type-safe Core Data query language.' spec.homepage = 'https://github.com/QueryKit/QueryKit/' spec.license = { :type => 'BSD', :file => 'LICENSE' } From a4b9f07f461050287358f46811ebd3099e1d2629 Mon Sep 17 00:00:00 2001 From: mxgc <62173553+mxgc@users.noreply.github.com> Date: Mon, 25 May 2020 03:18:20 -0700 Subject: [PATCH 3/4] fix: add library product to Package.swift (#57) --- Package.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Package.swift b/Package.swift index d661163..ebd1d10 100644 --- a/Package.swift +++ b/Package.swift @@ -5,6 +5,7 @@ import PackageDescription let package = Package( name: "QueryKit", products: [ + .library(name: "QueryKit", targets: ["QueryKit"]), ], targets: [ .target(name: "QueryKit", dependencies: []), From 6542e1129885173d31cc6206855bd8abb52b446a Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Thu, 10 Jun 2021 18:26:06 +0100 Subject: [PATCH 4/4] perf: optimise queryset exists --- Sources/QueryKit/QuerySet.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/QueryKit/QuerySet.swift b/Sources/QueryKit/QuerySet.swift index a1603bb..c63d7a8 100644 --- a/Sources/QueryKit/QuerySet.swift +++ b/Sources/QueryKit/QuerySet.swift @@ -223,8 +223,11 @@ extension QuerySet { :note: Returns nil if the operation could not be completed. */ public func exists() throws -> Bool { - let result:Int = try count() - return result > 0 + let fetchRequest = self.fetchRequest + fetchRequest.fetchLimit = 1 + + let result = try context.count(for: fetchRequest) + return result != 0 } // MARK: Deletion