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"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "DEBUG_BLUR_HASH"
value = "1"
isEnabled = "NO">
</EnvironmentVariable>
</EnvironmentVariables>
</LaunchAction>
<ProfileAction

View File

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