Prevent redundant status database lookups

This commit is contained in:
Shadowfacts 2020-06-15 23:22:34 -04:00
parent d27bddb2ca
commit 5d751cd994
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
5 changed files with 21 additions and 21 deletions

View File

@ -43,7 +43,7 @@ class ComposeStatusReplyView: UIView {
displayNameLabel.updateForAccountDisplayName(account: status.account) displayNameLabel.updateForAccountDisplayName(account: status.account)
usernameLabel.text = "@\(status.account.acct)" usernameLabel.text = "@\(status.account.acct)"
statusContentTextView.overrideMastodonController = mastodonController statusContentTextView.overrideMastodonController = mastodonController
statusContentTextView.statusID = status.id statusContentTextView.setTextFrom(status: status)
avatarRequest = ImageCache.avatars.get(status.account.avatar) { [weak self] (data) in avatarRequest = ImageCache.avatars.get(status.account.avatar) { [weak self] (data) in
guard let self = self, let data = data else { return } guard let self = self, let data = data else { return }

View File

@ -86,7 +86,7 @@ class BaseStatusTableViewCell: UITableViewCell {
accessibilityElements = [displayNameLabel!, contentWarningLabel!, collapseButton!, contentTextView!, attachmentsView!] accessibilityElements = [displayNameLabel!, contentWarningLabel!, collapseButton!, contentTextView!, attachmentsView!]
attachmentsView.isAccessibilityElement = true attachmentsView.isAccessibilityElement = true
NotificationCenter.default.addObserver(self, selector: #selector(updateUIForPreferences), name: .preferencesChanged, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil)
} }
open func createObserversIfNecessary() { open func createObserversIfNecessary() {
@ -125,8 +125,7 @@ class BaseStatusTableViewCell: UITableViewCell {
let account = status.account let account = status.account
self.accountID = account.id self.accountID = account.id
updateUI(account: account) updateUI(account: account)
updateUIForPreferences(account: account)
updateUIForPreferences()
attachmentsView.updateUI(status: status) attachmentsView.updateUI(status: status)
attachmentsView.isAccessibilityElement = status.attachments.count > 0 attachmentsView.isAccessibilityElement = status.attachments.count > 0
@ -134,7 +133,7 @@ class BaseStatusTableViewCell: UITableViewCell {
updateStatusState(status: status) updateStatusState(status: status)
contentTextView.statusID = statusID contentTextView.setTextFrom(status: status)
contentWarningLabel.text = status.spoilerText contentWarningLabel.text = status.spoilerText
contentWarningLabel.isHidden = status.spoilerText.isEmpty contentWarningLabel.isHidden = status.spoilerText.isEmpty
@ -191,8 +190,12 @@ class BaseStatusTableViewCell: UITableViewCell {
} }
} }
@objc func updateUIForPreferences() { @objc func preferencesChanged() {
guard let mastodonController = mastodonController, let account = mastodonController.persistentContainer.account(for: accountID) else { return } guard let mastodonController = mastodonController, let account = mastodonController.persistentContainer.account(for: accountID) else { return }
updateUIForPreferences(account: account)
}
func updateUIForPreferences(account: AccountMO) {
avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView) avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView)
displayNameLabel.updateForAccountDisplayName(account: account) displayNameLabel.updateForAccountDisplayName(account: account)
attachmentsView.contentHidden = Preferences.shared.blurAllMedia || (mastodonController.persistentContainer.status(for: statusID)?.sensitive ?? false) attachmentsView.contentHidden = Preferences.shared.blurAllMedia || (mastodonController.persistentContainer.status(for: statusID)?.sensitive ?? false)

View File

@ -63,8 +63,8 @@ class ConversationMainStatusTableViewCell: BaseStatusTableViewCell {
profileAccessibilityElement.accessibilityLabel = account.displayNameWithoutCustomEmoji profileAccessibilityElement.accessibilityLabel = account.displayNameWithoutCustomEmoji
} }
@objc override func updateUIForPreferences() { override func updateUIForPreferences(account: AccountMO) {
super.updateUIForPreferences() super.updateUIForPreferences(account: account)
favoriteAndReblogCountStackView.isHidden = !Preferences.shared.showFavoriteAndReblogCounts favoriteAndReblogCountStackView.isHidden = !Preferences.shared.showFavoriteAndReblogCounts
} }

View File

@ -69,6 +69,7 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
status = rebloggedStatus status = rebloggedStatus
realStatusID = rebloggedStatus.id realStatusID = rebloggedStatus.id
reblogLabel.isHidden = false reblogLabel.isHidden = false
updateRebloggerLabel(reblogger: status.account)
} else { } else {
reblogStatusID = nil reblogStatusID = nil
rebloggerID = nil rebloggerID = nil
@ -85,8 +86,8 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
timestampLabel.isHidden = !pinImageView.isHidden timestampLabel.isHidden = !pinImageView.isHidden
} }
@objc override func updateUIForPreferences() { @objc override func preferencesChanged() {
super.updateUIForPreferences() super.preferencesChanged()
if let rebloggerID = rebloggerID, if let rebloggerID = rebloggerID,
let reblogger = mastodonController.persistentContainer.account(for: rebloggerID) { let reblogger = mastodonController.persistentContainer.account(for: rebloggerID) {
updateRebloggerLabel(reblogger: reblogger) updateRebloggerLabel(reblogger: reblogger)

View File

@ -11,17 +11,13 @@ import Pachyderm
class StatusContentTextView: ContentTextView { class StatusContentTextView: ContentTextView {
var statusID: String? { private var statusID: String?
didSet {
guard let statusID = statusID else { return } func setTextFrom(status: StatusMO) {
guard let mastodonController = mastodonController, statusID = status.id
let status = mastodonController.persistentContainer.status(for: statusID) else {
fatalError("Can't set StatusContentTextView text without cached status for \(statusID)")
}
setTextFromHtml(status.content) setTextFromHtml(status.content)
setEmojis(status.emojis) setEmojis(status.emojis)
} }
}
override func getMention(for url: URL, text: String) -> Mention? { override func getMention(for url: URL, text: String) -> Mention? {
let mention: Mention? let mention: Mention?