mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-03-11 05:19:13 +00:00
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:
@@ -740,7 +740,7 @@
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEVELOPMENT_TEAM = 8JGND254B7;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 17;
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.neon443.StickerSlackTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
@@ -763,7 +763,7 @@
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEVELOPMENT_TEAM = 8JGND254B7;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
|
||||
IPHONEOS_DEPLOYMENT_TARGET = 17;
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.neon443.StickerSlackTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
|
||||
@@ -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 }
|
||||
|
||||
await withDiscardingTaskGroup { group in
|
||||
try? await withThrowingDiscardingTaskGroup { group in
|
||||
var i = 0
|
||||
let maxTasks = ProcessInfo.processInfo.processorCount-1
|
||||
var activeTasks = 0
|
||||
|
||||
for emoji in hoarder.emojis {
|
||||
i+=1
|
||||
group.addTask {
|
||||
if activeTasks >= maxTasks {
|
||||
let ib4 = i
|
||||
while i <= ib4 {
|
||||
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)")
|
||||
}
|
||||
activeTasks -= 1
|
||||
}
|
||||
group.addTask {
|
||||
try? await doThing(on: emoji, i: &i)
|
||||
activeTasks -= 1
|
||||
}
|
||||
activeTasks += 1
|
||||
}
|
||||
}
|
||||
|
||||
// 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)")
|
||||
// }
|
||||
|
||||
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)
|
||||
print("\(i)/\(downloadedEmojisBefore) \(emoji.name)")
|
||||
i+=1
|
||||
print("\(i)/\(downloadedEmojisBefore.count) \(emoji.name)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
let _ = emoji.sticker?.validate()
|
||||
i+=1
|
||||
print("\(i)/\(hoarder.emojis.count) \(emoji.name)")
|
||||
} catch {
|
||||
try! await doThing(on: emoji, i: &i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user