Răsfoiți Sursa

feat: 移除原用户缓存逻辑

陈文艺 2 zile în urmă
părinte
comite
42519fc5e5

+ 1 - 94
Lanu/Manager/Profile/LNProfileManager.swift

@@ -43,11 +43,6 @@ class LNProfileManager {
     
     private var randomProfile: LNRandomProfileResponse?
     
-    private static let profileCacheLimit = 300
-    private var profileCache: [String: LNProfileUserInfo] = [:]
-    private var profileCacheOrder: [String] = []
-    private let profileCacheLock = NSLock()
-    
     private let captchaCoolDown = 60
     private var captchaRemain = 0
     private var captchaTimer: Timer?
@@ -131,16 +126,7 @@ extension LNProfileManager {
             guard let self else { return }
             if let res, err == nil {
                 res.list.forEach {
-                    if $0.userNo.isMyUid {
-                        if self.myUserInfo.update($0) {
-                            self.notifyUserInfoChanged(newInfo: $0)
-                        }
-                    } else {
-                        self.updateProfileCache(
-                            uid: $0.userNo,
-                            name: $0.nickname,
-                            avatar: $0.avatar
-                        )
+                    if !$0.userNo.isMyUid || self.myUserInfo.update($0) {
                         self.notifyUserInfoChanged(newInfo: $0)
                     }
                 }
@@ -180,85 +166,6 @@ extension LNProfileManager {
 //    }
 }
 
-extension LNProfileManager {
-    func getCachedProfileUserInfo(uid: String) -> LNProfileUserInfo? {
-        profileCacheLock.lock()
-        defer { profileCacheLock.unlock() }
-        guard let info = profileCache[uid] else {
-            return nil
-        }
-        touchProfileCacheKey(uid)
-        return info
-    }
-    
-    func getCachedProfileUserInfo(uid: String,
-                                  fetchIfNeeded: Bool = true,
-                                  queue: DispatchQueue = .main,
-                                  handler: @escaping (LNProfileUserInfo?) -> Void) {
-        if let info = getCachedProfileUserInfo(uid: uid) {
-            queue.asyncIfNotGlobal {
-                handler(info)
-            }
-            return
-        }
-        
-        guard fetchIfNeeded else {
-            queue.asyncIfNotGlobal {
-                handler(nil)
-            }
-            return
-        }
-        
-        getUserProfileDetail(uid: uid, queue: queue) { [weak self] profile in
-            guard let self, let profile else {
-                handler(nil)
-                return
-            }
-            
-            self.updateProfileCache(
-                uid: profile.userNo,
-                name: profile.nickname,
-                avatar: profile.avatar
-            )
-            handler(self.getCachedProfileUserInfo(uid: uid))
-        }
-    }
-    
-    func updateProfileCache(uid: String,
-                            name: String,
-                            avatar: String) {
-        guard !uid.isEmpty else {
-            return
-        }
-        
-        profileCacheLock.lock()
-        defer { profileCacheLock.unlock() }
-        
-        let info = profileCache[uid] ?? LNProfileUserInfo()
-        info.uid = uid
-        info.name = name
-        info.avatar = avatar
-        
-        profileCache[uid] = info
-        touchProfileCacheKey(uid)
-        trimProfileCacheIfNeeded()
-    }
-    
-    private func touchProfileCacheKey(_ uid: String) {
-        if let index = profileCacheOrder.firstIndex(of: uid) {
-            profileCacheOrder.remove(at: index)
-        }
-        profileCacheOrder.append(uid)
-    }
-    
-    private func trimProfileCacheIfNeeded() {
-        while profileCacheOrder.count > Self.profileCacheLimit {
-            let expiredUid = profileCacheOrder.removeFirst()
-            profileCache.removeValue(forKey: expiredUid)
-        }
-    }
-}
-
 extension LNProfileManager {
     func getBindPhoneCaptcha(code: String, phone: String,
                              queue: DispatchQueue = .main,

+ 3 - 4
Lanu/Views/Room/Base/Views/Gift/LNRoomGiftHeaderView.swift

@@ -285,11 +285,10 @@ private class LNRoomGiftSpecifiedUserView: UIView {
             return
         }
         
-        LNProfileManager.shared.getCachedProfileUserInfo(uid: uid, fetchIfNeeded: true)
-        { [weak self] info in
+        LNProfileManager.shared.getUserProfileDetail(uid: uid) { [weak self] info in
             guard let self else { return }
-            guard let info, info.uid == curUid else { return }
-            nameLabel.text = info.name
+            guard let info, info.userNo == curUid else { return }
+            nameLabel.text = info.nickname
             avatar.sd_setImage(with: URL(string: info.avatar))
         }
     }

+ 2 - 10
Lanu/Views/Room/OrderRoom/Seats/LNOrderRoomUserSeatView.swift

@@ -226,16 +226,8 @@ extension LNOrderRoomUserSeatView: LNRoomViewModelNotify {
         } else {
             userView.isHidden = false
             
-            if !curSeat.nickname.isEmpty {
-                userAvatar.sd_setImage(with: URL(string: curSeat.avatar))
-                nameLabel.text = curSeat.nickname
-            } else {
-                LNProfileManager.shared.getCachedProfileUserInfo(uid: curSeat.uid) { [weak self] info in
-                    guard let self, let info, info.uid == curSeat.uid else { return }
-                    userAvatar.sd_setImage(with: URL(string: info.avatar))
-                    nameLabel.text = info.name
-                }
-            }
+            userAvatar.sd_setImage(with: URL(string: curSeat.avatar))
+            nameLabel.text = curSeat.nickname
         }
         
         muteIc.isHidden = !curSeat.isMute

+ 0 - 7
Lanu/Views/Room/OrderRoom/ViewModel/LNOrderRoomViewModel.swift

@@ -45,9 +45,6 @@ extension LNOrderRoomViewModel {
             runOnMain {
                 handler(res)
             }
-            res?.list.forEach {
-                LNProfileManager.shared.updateProfileCache(uid: $0.user.userNo, name: $0.user.nickname, avatar: $0.user.avatar)
-            }
             if let err {
                 showToast(err.errorDesc)
             }
@@ -78,10 +75,6 @@ extension LNOrderRoomViewModel {
                 handler(res)
             }
             
-            res?.list.forEach {
-                LNProfileManager.shared.updateProfileCache(uid: $0.user.userNo, name: $0.user.nickname, avatar: $0.user.avatar)
-            }
-            
             if let err {
                 showToast(err.errorDesc)
             }