mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-28 05:53:59 +02:00
Fix holding onto frozen Realm reference
This commit is contained in:
parent
8c87b31e56
commit
5c76158729
1 changed files with 9 additions and 5 deletions
|
@ -9,10 +9,17 @@ import Foundation
|
||||||
import RealmSwift
|
import RealmSwift
|
||||||
|
|
||||||
class Store {
|
class Store {
|
||||||
private static var _serverConfig: ServerConnectionConfig?
|
|
||||||
public static var serverConfig: ServerConnectionConfig? {
|
public static var serverConfig: ServerConnectionConfig? {
|
||||||
get {
|
get {
|
||||||
return _serverConfig
|
do {
|
||||||
|
// Fetch each time, as holding onto a live or frozen realm object is bad
|
||||||
|
let index = Database.shared.getLastActiveConfigIndex()
|
||||||
|
let realm = try Realm()
|
||||||
|
return realm.objects(ServerConnectionConfig.self).first(where: { $0.index == index })
|
||||||
|
} catch {
|
||||||
|
debugPrint(error)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
set(updated) {
|
set(updated) {
|
||||||
if updated != nil {
|
if updated != nil {
|
||||||
|
@ -20,9 +27,6 @@ class Store {
|
||||||
} else {
|
} else {
|
||||||
Database.shared.setLastActiveConfigIndexToNil()
|
Database.shared.setLastActiveConfigIndexToNil()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make safe for accessing on all threads
|
|
||||||
_serverConfig = updated?.freeze()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue