Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Searchkit memory leaks #1735

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "41fcbec1ecbb7853d9ead798bba9d46f35f28767f4d41a009c8eeee022e99a84",
"originHash" : "3f6921a5ec30d1ecb6d6b205cf27a816c318246bb00f0ea367b997cc66527d32",
"pins" : [
{
"identity" : "anycodable",
Expand Down Expand Up @@ -85,7 +85,7 @@
{
"identity" : "logstream",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Wouter01/LogStream",
"location" : "https://github.com/CodeEditApp/LogStream",
"state" : {
"revision" : "6f83694b2675dcf3b1cea0a52546ff4469c18282",
"version" : "1.3.0"
Expand Down
6 changes: 3 additions & 3 deletions CodeEdit/Features/Documents/Indexer/SearchIndexer+Add.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension SearchIndexer {
}

return modifyIndexQueue.sync {
SKIndexAddDocumentWithText(index, document.takeUnretainedValue(), text as CFString, canReplace)
SKIndexAddDocumentWithText(index, document.takeRetainedValue(), text as CFString, canReplace)
}
}

Expand Down Expand Up @@ -66,7 +66,7 @@ extension SearchIndexer {
let mime = mimeType ?? self.detectMimeType(fileURL)

return modifyIndexQueue.sync {
SKIndexAddDocument(index, document.takeUnretainedValue(), mime as CFString?, canReplace)
SKIndexAddDocument(index, document.takeRetainedValue(), mime as CFString?, canReplace)
}
}

Expand Down Expand Up @@ -107,7 +107,7 @@ extension SearchIndexer {
/// - Returns: `true` if the document was successfully removed, `false` otherwise.
/// **Note:** If the document didn't exist, this also returns `true`.
public func removeDocument(url: URL) -> Bool {
let document = SKDocumentCreateWithURL(url as CFURL).takeUnretainedValue()
let document = SKDocumentCreateWithURL(url as CFURL).takeRetainedValue()
return self.remove(document: document)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,24 @@ extension SearchIndexer {

var isLeaf = true

let iterator = SKIndexDocumentIteratorCreate(index, inParentDocument).takeUnretainedValue()
let iterator = SKIndexDocumentIteratorCreate(index, inParentDocument).takeRetainedValue()
while let skDocument = SKIndexDocumentIteratorCopyNext(iterator) {
isLeaf = false
self.addLeafURLs(index: index, inParentDocument: skDocument.takeUnretainedValue(), docs: &docs)
self.addLeafURLs(index: index, inParentDocument: skDocument.takeRetainedValue(), docs: &docs)
}

if isLeaf, inParentDocument != nil,
kSKDocumentStateNotIndexed != SKIndexGetDocumentState(index, inParentDocument) {
if let temp = SKDocumentCopyURL(inParentDocument) {
let baseURL = temp.takeUnretainedValue() as URL
let documentID = SKIndexGetDocumentID(index, inParentDocument)
docs.append(
DocumentID(
url: baseURL,
document: inParentDocument!,
documentID: documentID
)
let url = SKDocumentCopyURL(inParentDocument).takeRetainedValue()

let documentID = SKIndexGetDocumentID(index, inParentDocument)
docs.append(
DocumentID(
url: url as URL,
document: inParentDocument!,
documentID: documentID
)
}
)

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extension SearchIndexer {

let partialResult: [SearchResult] = zip(urls[0..<foundCount], scores)
.compactMap { (cfurl, score) -> SearchResult? in
guard let url = cfurl?.takeUnretainedValue() as URL? else {
guard let url = cfurl?.takeRetainedValue() as URL? else {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions CodeEdit/Features/Documents/Indexer/SearchIndexer+Terms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ extension SearchIndexer {

var result = [TermCount]()

let document = SKDocumentCreateWithURL(url as CFURL).takeUnretainedValue()
let document = SKDocumentCreateWithURL(url as CFURL).takeRetainedValue()
let documentID = SKIndexGetDocumentID(index, document)

guard let termVals = SKIndexCopyTermIDArrayForDocumentID(index, documentID),
let terms = termVals.takeUnretainedValue() as? [CFIndex] else {
let terms = termVals.takeRetainedValue() as? [CFIndex] else {
return []
}

Expand Down
2 changes: 1 addition & 1 deletion CodeEdit/Features/Documents/Indexer/SearchIndexer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class SearchIndexer {
private(set) lazy var stopWords: Set<String> = {
var stopWords: Set<String> = []
if let index = self.index,
let properties = SKIndexGetAnalysisProperties(self.index).takeUnretainedValue() as? [String: Any],
let properties = SKIndexGetAnalysisProperties(self.index).takeRetainedValue() as? [String: Any],
let newStopWords = properties[kSKStopWords as String] as? Set<String> {
stopWords = newStopWords
}
Expand Down
Loading