Skip to content

Commit

Permalink
Attempt to fix stale data bug by setting keepSynced in DatabaseContro…
Browse files Browse the repository at this point in the history
…ller
  • Loading branch information
joelrorseth committed Oct 15, 2017
1 parent f28ef69 commit c2c7b43
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion AtMe/AuthController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)>")
Expand Down
2 changes: 1 addition & 1 deletion AtMe/DatabaseController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c2c7b43

Please sign in to comment.