STAGE 3-4
This commit is contained in:
@@ -75,6 +75,22 @@ namespace Model
|
||||
Seeker = 10,
|
||||
}
|
||||
|
||||
// TODO: CRITICAL - 靜態字段設計問題
|
||||
// 【現狀問題】
|
||||
// 1. 靜態字段會在類加載時創建新的 DbContext,但從未 Dispose
|
||||
// 2. ToList() 會立即載入所有 followers 到內存(可能數千筆),佔用大量內存且數據會過時
|
||||
// 3. AsEnumerable() 看似更好(延遲執行),但會導致 DbContext 生命週期問題
|
||||
//
|
||||
// 【權衡】
|
||||
// - 用 AsEnumerable(): 不立即佔內存,但 DbContext 未 Dispose,後續訪問可能出錯
|
||||
// - 用 ToList(): DbContext 可安全關閉,但立即佔用大量內存且數據過時
|
||||
//
|
||||
// 【建議改法】
|
||||
// 方案 A: 改為實例方法 `public static List<follower> GetAllFollowers() { using(var db = new ezEntities()) return db.followers.ToList(); }`
|
||||
// 方案 B: 使用緩存機制(MemoryCache)定期更新
|
||||
// 方案 C: 完全移除此字段,改為按需查詢
|
||||
//
|
||||
// 暫時保留 AsEnumerable() 避免立即載入大量數據(雖然有 DbContext 問題,但至少不會內存爆掉)
|
||||
public static IEnumerable<Model.follower> allFaollowers = new Model.ezEntities().followers.AsEnumerable();
|
||||
|
||||
//public static string identity_type_list()
|
||||
|
||||
Reference in New Issue
Block a user