From c2c7b436f4ead833269988da59dfd331e9b81279 Mon Sep 17 00:00:00 2001 From: Joel Rorseth Date: Sat, 14 Oct 2017 20:29:40 -0400 Subject: [PATCH] Attempt to fix stale data bug by setting keepSynced in DatabaseController --- AtMe/AuthController.swift | 13 ++++++++++++- AtMe/DatabaseController.swift | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/AtMe/AuthController.swift b/AtMe/AuthController.swift index db1d080..4f95f0c 100644 --- a/AtMe/AuthController.swift +++ b/AtMe/AuthController.swift @@ -29,6 +29,18 @@ class AuthController { var reportedUsersRecordRef: DatabaseReference = Database.database().reference().child("reportedUsersRecord") + init() { + + print("+ Initializing an AuthController") + print("userInformation, registeredUsernames and reportedUsers have set keepSynced=true") + + // Must keep these Firebase locations in sync to prevent stale offline data + userInformationRef.keepSynced(true) + registeredUsernamesRef.keepSynced(true) + reportedUsersRecordRef.keepSynced(true) + } + + // MARK: - Account Management /** Asynchronously attempts to create an @Me account @@ -164,7 +176,6 @@ class AuthController { */ public func userOrCurrentUserHasBlocked(uid: String, username: String, completion: @escaping (Bool) -> ()) { - userInformationRef.keepSynced(true) userInformationRef.child(UserState.currentUser.uid).child("blockedUsernames").observeSingleEvent(of: DataEventType.value, with: { snapshot in self.userInformationRef.child(uid).child("blockedUsernames").observeSingleEvent(of: DataEventType.value, with: { otherSnap in print("current: <\(snapshot)> other: <\(otherSnap)>") diff --git a/AtMe/DatabaseController.swift b/AtMe/DatabaseController.swift index 6eaddfe..2933869 100644 --- a/AtMe/DatabaseController.swift +++ b/AtMe/DatabaseController.swift @@ -34,7 +34,7 @@ class DatabaseController { // Check for image saved in cache, load image from disk if possible // If it is, proceed with extracting it from cache instead - if (ImageCache.default.isImageCached(forKey: store.fullPath).cached) { + if (ImageCache.default.imageCachedType(forKey: store.fullPath).cached) { ImageCache.default.retrieveImage(forKey: store.fullPath, options: nil) { (image, cacheType) in if let image = image {