From de67327f6d02fec06e070d2dc115f1f55dbd24aa Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 18 Jan 2021 13:46:07 -0500 Subject: [PATCH] Fix ImageCache kicking off extra requests when a completion block was not provided --- Tusker/Caching/ImageCache.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Tusker/Caching/ImageCache.swift b/Tusker/Caching/ImageCache.swift index 38f7943559..2441b5e62c 100644 --- a/Tusker/Caching/ImageCache.swift +++ b/Tusker/Caching/ImageCache.swift @@ -42,13 +42,18 @@ class ImageCache { // of the state (unknown/exists/does not exist) of whether or not objects exist on disk so that the slow, disk I/O // path can be avoided most of the time let entry = try? cache.get(key) { - backgroundQueue.async { - completion?(entry.data, entry.image) + if let completion = completion { + backgroundQueue.async { + completion(entry.data, entry.image) + } } return nil } else { - if let completion = completion, let group = groups[url] { - return group.addCallback(completion) + if let group = groups[url] { + if let completion = completion { + return group.addCallback(completion) + } + return nil } else { let group = RequestGroup(url: url) { (data, image) in if let data = data {