finally wrote a funcitonal good test!!!!

added undownloadedemojisbefore unused atm
using a withThrowingDiscardingTaskGroup with a task limit
    task limit: max tasks is cores-1
    every tiem a task is added taskcount+=1
    every tiem it finishes taskcount -= 1
    if active tasks> maxtasks wait until i > what it was before
        reduce activetasks by one

deleting images in pass 2
guard that it was downloaded before
basic async cos i cba atp
doThing wiht inout i to increment
    itll download the image and make sure its not already downloaded etc
This commit is contained in:
neon443
2025-10-30 23:15:18 +00:00
parent ff123811a0
commit be22370ec0
2 changed files with 40 additions and 25 deletions

View File

@@ -50,38 +50,53 @@ struct PerformanceTests {
}
@Test func MSStickerValidation() async throws {
let undownloadedEmojisBefore = hoarder.emojis.filter { !$0.isLocal }.map { $0.id }
let downloadedEmojisBefore = hoarder.emojis.filter { $0.isLocal }.map { $0.id }
try? await withThrowingDiscardingTaskGroup { group in
var i = 0
let maxTasks = ProcessInfo.processInfo.processorCount-1
var activeTasks = 0
for emoji in hoarder.emojis {
if activeTasks >= maxTasks {
let ib4 = i
while i <= ib4 {
try? await Task.sleep(nanoseconds: 1)
}
activeTasks -= 1
}
group.addTask {
try? await doThing(on: emoji, i: &i)
activeTasks -= 1
}
activeTasks += 1
}
}
await withDiscardingTaskGroup { group in
var i = 0
for emoji in hoarder.emojis {
emoji.deleteImage()
guard downloadedEmojisBefore.contains(emoji.id) else { continue }
async let (data, _) = try! URLSession.shared.data(from: emoji.remoteImageURL)
try! await data.write(to: emoji.localImageURL)
i+=1
group.addTask {
try? await Task.sleep(nanoseconds: 1)
async let (data, _) = try! URLSession.shared.data(from: emoji.remoteImageURL)
try! await data.write(to: emoji.localImageURL)
let _ = emoji.sticker?.validate()
print("\(i)/\(hoarder.emojis.count) \(emoji.name)")
}
print("\(i)/\(downloadedEmojisBefore.count) \(emoji.name)")
}
}
// var i = 0
// for emoji in hoarder.emojis {
// i+=1
// async let (data, _) = try! URLSession.shared.data(from: emoji.remoteImageURL)
// try! await data.write(to: emoji.localImageURL)
// let _ = emoji.sticker?.validate()
// print("\(i)/\(hoarder.emojis.count) \(emoji.name)")
// }
var i = 0
for emoji in hoarder.emojis {
emoji.deleteImage()
guard downloadedEmojisBefore.contains(emoji.id) else { continue }
async let (data, _) = try! URLSession.shared.data(from: emoji.remoteImageURL)
}
func doThing(on emoji: Emoji, i: inout Int) async throws {
do {
guard !emoji.isLocal else { return }
async let (data, _) = try URLSession.shared.data(from: emoji.remoteImageURL)
try! await data.write(to: emoji.localImageURL)
print("\(i)/\(downloadedEmojisBefore) \(emoji.name)")
let _ = emoji.sticker?.validate()
i+=1
print("\(i)/\(hoarder.emojis.count) \(emoji.name)")
} catch {
try! await doThing(on: emoji, i: &i)
}
}
}