From 9507343511b89f1ca8d3788824b9684b5a05ab85 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Sat, 3 Oct 2020 13:55:07 -0700 Subject: [PATCH] Refactoring --- DB/Sources/DB/Content/ContentDatabase.swift | 11 +++-------- .../ServiceLayer/Services/ProfileService.swift | 2 -- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/DB/Sources/DB/Content/ContentDatabase.swift b/DB/Sources/DB/Content/ContentDatabase.swift index 0f58337..92312d9 100644 --- a/DB/Sources/DB/Content/ContentDatabase.swift +++ b/DB/Sources/DB/Content/ContentDatabase.swift @@ -218,17 +218,12 @@ public extension ContentDatabase { .eraseToAnyPublisher() } - func accountObservation(id: String) -> AnyPublisher { + func accountObservation(id: String) -> AnyPublisher { ValueObservation.tracking(AccountInfo.request(AccountRecord.filter(AccountRecord.Columns.id == id)).fetchOne) .removeDuplicates() - .map { - if let info = $0 { - return Account(info: info) - } else { - return nil - } - } .publisher(in: databaseWriter) + .compactMap { $0 } + .map(Account.init(info:)) .eraseToAnyPublisher() } diff --git a/ServiceLayer/Sources/ServiceLayer/Services/ProfileService.swift b/ServiceLayer/Sources/ServiceLayer/Services/ProfileService.swift index 3352bf7..ce5205e 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/ProfileService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/ProfileService.swift @@ -35,8 +35,6 @@ public struct ProfileService { self.contentDatabase = contentDatabase var accountPublisher = contentDatabase.accountObservation(id: accountID) - .compactMap { $0 } - .eraseToAnyPublisher() if let account = account { accountPublisher = accountPublisher