Use a single disptach queue for attachment/card thumbnails

This commit is contained in:
Shadowfacts 2021-11-24 15:02:35 -05:00
parent 7b79cec0ed
commit d1083116e0
3 changed files with 11 additions and 6 deletions

View File

@ -99,6 +99,11 @@
value = "1" value = "1"
isEnabled = "NO"> isEnabled = "NO">
</EnvironmentVariable> </EnvironmentVariable>
<EnvironmentVariable
key = "DEBUG_BLUR_HASH"
value = "1"
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables> </EnvironmentVariables>
</LaunchAction> </LaunchAction>
<ProfileAction <ProfileAction

View File

@ -17,6 +17,8 @@ protocol AttachmentViewDelegate: AnyObject {
class AttachmentView: GIFImageView { class AttachmentView: GIFImageView {
static let queue = DispatchQueue(label: "Attachment Thumbnail", qos: .userInitiated, attributes: .concurrent)
weak var delegate: AttachmentViewDelegate? weak var delegate: AttachmentViewDelegate?
var playImageView: UIImageView? var playImageView: UIImageView?
@ -108,7 +110,7 @@ class AttachmentView: GIFImageView {
} }
if let hash = attachment.blurHash { if let hash = attachment.blurHash {
DispatchQueue.global(qos: .default).async { [weak self] in AttachmentView.queue.async { [weak self] in
guard let self = self else { return } guard let self = self else { return }
let size: CGSize let size: CGSize
if let meta = self.attachment.meta, if let meta = self.attachment.meta,
@ -191,8 +193,7 @@ class AttachmentView: GIFImageView {
}) })
} else { } else {
let attachmentURL = self.attachment.url let attachmentURL = self.attachment.url
// todo: use a single dispatch queue AttachmentView.queue.async {
DispatchQueue.global(qos: .userInitiated).async {
let asset = AVURLAsset(url: attachmentURL) let asset = AVURLAsset(url: attachmentURL)
let generator = AVAssetImageGenerator(asset: asset) let generator = AVAssetImageGenerator(asset: asset)
generator.appliesPreferredTrackTransform = true generator.appliesPreferredTrackTransform = true
@ -237,7 +238,7 @@ class AttachmentView: GIFImageView {
func loadGifv() { func loadGifv() {
let attachmentURL = self.attachment.url let attachmentURL = self.attachment.url
let asset = AVURLAsset(url: attachmentURL) let asset = AVURLAsset(url: attachmentURL)
DispatchQueue.global(qos: .userInitiated).async { AttachmentView.queue.async {
let generator = AVAssetImageGenerator(asset: asset) let generator = AVAssetImageGenerator(asset: asset)
generator.appliesPreferredTrackTransform = true generator.appliesPreferredTrackTransform = true
guard let image = try? generator.copyCGImage(at: .zero, actualTime: nil) else { return } guard let image = try? generator.copyCGImage(at: .zero, actualTime: nil) else { return }

View File

@ -163,8 +163,7 @@ class StatusCardView: UIView {
let imageViewSize = self.imageView.bounds.size let imageViewSize = self.imageView.bounds.size
// todo: merge this code with AttachmentView, use a single DispatchQueue AttachmentView.queue.async { [weak self] in
DispatchQueue.global(qos: .default).async { [weak self] in
guard let self = self else { return } guard let self = self else { return }
let size: CGSize let size: CGSize