Skip to content

Commit

Permalink
fix: query findAll() throwing hang risk warning (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 authored Nov 7, 2022
1 parent 4a52629 commit 57de231
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Parse-Swift Changelog

### main
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/4.16.0...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/4.16.1...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
* _Contributing to this repo? Add info about your change here to be included in the next release_

### 4.16.0
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/4.16.0...4.16.1), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/4.16.1/documentation/parseswift)

__Fixes__
- Querying using findAll throws a hang risk warning in Xcode 14 ([#14](https://github.com/netreconlab/Parse-Swift/pull/10)), thanks to [Corey Baker](https://github.com/cbaker6).

### 4.16.0
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/4.15.2...4.16.0), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/4.16.0/documentation/parseswift)

Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/ParseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

enum ParseConstants {
static let sdk = "swift"
static let version = "4.16.0"
static let version = "4.16.1"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
static let fileManagementLibraryDirectory = "Library/"
Expand Down
50 changes: 43 additions & 7 deletions Sources/ParseSwift/Types/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -642,20 +642,55 @@ extension Query: Queryable {
completion(.failure(error))
return
}

#if compiler(>=5.5.2) && canImport(_Concurrency)
Task {
var query = self
.order([.ascending("objectId")])
query.limit = limit ?? ParseConstants.batchLimit
var results = [ResultType]()
var finished = false
while !finished {
do {
let currentResults = try await query.findCommand().executeAsync(options: options,
callbackQueue: callbackQueue)
results.append(contentsOf: currentResults)
if currentResults.count >= query.limit {
guard let lastObjectId = results[results.count - 1].objectId else {
throw ParseError(code: .unknownError, message: "Last object should have an id.")
}
query.where.add("objectId" > lastObjectId)
} else {
finished = true
}
} catch {
let defaultError = ParseError(code: .unknownError,
message: error.localizedDescription)
let parseError = error as? ParseError ?? defaultError
callbackQueue.async {
completion(.failure(parseError))
}
return
}
}
let finalResults = results
callbackQueue.async {
completion(.success(finalResults))
}
}
#else
var query = self
.order([.ascending("objectId")])
query.limit = limit ?? ParseConstants.batchLimit
var results = [ResultType]()
var finished = false
let uuid = UUID()
let queue = DispatchQueue(label: "com.parse.findAll.\(uuid)",
qos: .default,
attributes: .concurrent,
autoreleaseFrequency: .inherit,
target: nil)
queue.sync {

var query = self
.order([.ascending("objectId")])
query.limit = limit ?? ParseConstants.batchLimit
var results = [ResultType]()
var finished = false

while !finished {
do {
let currentResults = try query.findCommand().execute(options: options)
Expand Down Expand Up @@ -683,6 +718,7 @@ extension Query: Queryable {
completion(.success(results))
}
}
#endif
}

/**
Expand Down

0 comments on commit 57de231

Please sign in to comment.