Refactoring
This commit is contained in:
parent
ce3618dcbe
commit
a92d95d229
|
@ -110,13 +110,8 @@ extension IdentityDatabase {
|
||||||
.eraseToAnyPublisher()
|
.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
func identitiesObservation() -> AnyPublisher<[Identity], Error> {
|
func identitiesObservation(excluding: String) -> AnyPublisher<[Identity], Error> {
|
||||||
ValueObservation.tracking(
|
ValueObservation.tracking(Self.identitiesRequest(excluding: excluding).fetchAll)
|
||||||
StoredIdentity
|
|
||||||
.including(optional: StoredIdentity.instance)
|
|
||||||
.including(optional: StoredIdentity.account)
|
|
||||||
.asRequest(of: IdentityResult.self)
|
|
||||||
.fetchAll)
|
|
||||||
.removeDuplicates()
|
.removeDuplicates()
|
||||||
.publisher(in: databaseQueue, scheduling: .immediate)
|
.publisher(in: databaseQueue, scheduling: .immediate)
|
||||||
.map { $0.map(Identity.init(result:)) }
|
.map { $0.map(Identity.init(result:)) }
|
||||||
|
@ -124,15 +119,7 @@ extension IdentityDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
func recentIdentitiesObservation(excluding: String) -> AnyPublisher<[Identity], Error> {
|
func recentIdentitiesObservation(excluding: String) -> AnyPublisher<[Identity], Error> {
|
||||||
ValueObservation.tracking(
|
ValueObservation.tracking(Self.identitiesRequest(excluding: excluding).limit(9).fetchAll)
|
||||||
StoredIdentity
|
|
||||||
.filter(Column("id") != excluding)
|
|
||||||
.order(Column("lastUsedAt").desc)
|
|
||||||
.limit(10)
|
|
||||||
.including(optional: StoredIdentity.instance)
|
|
||||||
.including(optional: StoredIdentity.account)
|
|
||||||
.asRequest(of: IdentityResult.self)
|
|
||||||
.fetchAll)
|
|
||||||
.removeDuplicates()
|
.removeDuplicates()
|
||||||
.publisher(in: databaseQueue, scheduling: .immediate)
|
.publisher(in: databaseQueue, scheduling: .immediate)
|
||||||
.map { $0.map(Identity.init(result:)) }
|
.map { $0.map(Identity.init(result:)) }
|
||||||
|
@ -145,6 +132,15 @@ extension IdentityDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension IdentityDatabase {
|
private extension IdentityDatabase {
|
||||||
|
private static func identitiesRequest(excluding: String) -> QueryInterfaceRequest<IdentityResult> {
|
||||||
|
StoredIdentity
|
||||||
|
.filter(Column("id") != excluding)
|
||||||
|
.order(Column("lastUsedAt").desc)
|
||||||
|
.including(optional: StoredIdentity.instance)
|
||||||
|
.including(optional: StoredIdentity.account)
|
||||||
|
.asRequest(of: IdentityResult.self)
|
||||||
|
}
|
||||||
|
|
||||||
private static func migrate(_ writer: DatabaseWriter) throws {
|
private static func migrate(_ writer: DatabaseWriter) throws {
|
||||||
var migrator = DatabaseMigrator()
|
var migrator = DatabaseMigrator()
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ extension IdentityRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
func identitiesObservation() -> AnyPublisher<[Identity], Error> {
|
func identitiesObservation() -> AnyPublisher<[Identity], Error> {
|
||||||
appEnvironment.identityDatabase.identitiesObservation()
|
appEnvironment.identityDatabase.identitiesObservation(excluding: identity.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func recentIdentitiesObservation() -> AnyPublisher<[Identity], Error> {
|
func recentIdentitiesObservation() -> AnyPublisher<[Identity], Error> {
|
||||||
|
|
Loading…
Reference in New Issue