From ff123811a0b270d57ce89fba410e4d65db1e1ff7 Mon Sep 17 00:00:00 2001 From: neon443 <69979447+neon443@users.noreply.github.com> Date: Thu, 30 Oct 2025 22:30:54 +0000 Subject: [PATCH] =?UTF-8?q?ultra=20parallelised=20download=20all=20in=20st?= =?UTF-8?q?icker=20vailidation=20performance=20Test=20the=20issue=20is=20t?= =?UTF-8?q?hat=20the=20counter=20doesnt=20work,=20and=20that=20it=20does?= =?UTF-8?q?=20crash=20if=20the=20network=20request=20times=20out=20?= =?UTF-8?q?=F0=9F=98=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StickerSlackTests/StickerSlackTests.swift | 36 ++++++++++++++++------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/StickerSlackTests/StickerSlackTests.swift b/StickerSlackTests/StickerSlackTests.swift index 675027a..a32155d 100644 --- a/StickerSlackTests/StickerSlackTests.swift +++ b/StickerSlackTests/StickerSlackTests.swift @@ -52,21 +52,35 @@ struct PerformanceTests { @Test func MSStickerValidation() async throws { let downloadedEmojisBefore = hoarder.emojis.filter { $0.isLocal }.map { $0.id } + await withDiscardingTaskGroup { group in + var i = 0 + for emoji in hoarder.emojis { + 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)") + } + } + } + +// 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 { - i+=1 - let (data, _) = try! await URLSession.shared.data(from: emoji.remoteImageURL) - try! data.write(to: emoji.localImageURL) - let _ = emoji.sticker?.validate() emoji.deleteImage() - print("\(i)/\(hoarder.emojis.count) \(emoji.name)") - } - - i = 0 - for emoji in hoarder.emojis { guard downloadedEmojisBefore.contains(emoji.id) else { continue } - let (data, _) = try! await URLSession.shared.data(from: emoji.remoteImageURL) - try! data.write(to: emoji.localImageURL) + async let (data, _) = try! URLSession.shared.data(from: emoji.remoteImageURL) + try! await data.write(to: emoji.localImageURL) print("\(i)/\(downloadedEmojisBefore) \(emoji.name)") } }