mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-03-11 13:26:17 +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;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
DEVELOPMENT_TEAM = 8JGND254B7;
|
DEVELOPMENT_TEAM = 8JGND254B7;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 17;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.neon443.StickerSlackTests;
|
PRODUCT_BUNDLE_IDENTIFIER = com.neon443.StickerSlackTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
@@ -763,7 +763,7 @@
|
|||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
DEVELOPMENT_TEAM = 8JGND254B7;
|
DEVELOPMENT_TEAM = 8JGND254B7;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 17;
|
||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.neon443.StickerSlackTests;
|
PRODUCT_BUNDLE_IDENTIFIER = com.neon443.StickerSlackTests;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
|||||||
@@ -50,38 +50,53 @@ struct PerformanceTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test func MSStickerValidation() async throws {
|
@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 }
|
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
|
await withDiscardingTaskGroup { group in
|
||||||
var i = 0
|
var i = 0
|
||||||
for emoji in hoarder.emojis {
|
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
|
i+=1
|
||||||
group.addTask {
|
print("\(i)/\(downloadedEmojisBefore.count) \(emoji.name)")
|
||||||
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)")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// var i = 0
|
|
||||||
// for emoji in hoarder.emojis {
|
func doThing(on emoji: Emoji, i: inout Int) async throws {
|
||||||
// i+=1
|
do {
|
||||||
// async let (data, _) = try! URLSession.shared.data(from: emoji.remoteImageURL)
|
guard !emoji.isLocal else { return }
|
||||||
// try! await data.write(to: emoji.localImageURL)
|
async let (data, _) = try URLSession.shared.data(from: emoji.remoteImageURL)
|
||||||
// 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)
|
|
||||||
try! await data.write(to: emoji.localImageURL)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user