Add list name to room summary provider logs to avoid confusion between multiple instances

This commit is contained in:
Stefan Ceriu
2023-05-16 12:38:06 +03:00
committed by Stefan Ceriu
parent 1af710d2b0
commit f1a26417bd
3 changed files with 27 additions and 22 deletions
@@ -465,13 +465,16 @@ class ClientProxy: ClientProxyProtocol {
} }
visibleRoomsSummaryProvider = RoomSummaryProvider(slidingSyncListProxy: visibleRoomsListProxy, visibleRoomsSummaryProvider = RoomSummaryProvider(slidingSyncListProxy: visibleRoomsListProxy,
eventStringBuilder: RoomEventStringBuilder(stateEventStringBuilder: RoomStateEventStringBuilder(userID: userID))) eventStringBuilder: RoomEventStringBuilder(stateEventStringBuilder: RoomStateEventStringBuilder(userID: userID)),
name: visibleRoomsListProxy.name)
allRoomsSummaryProvider = RoomSummaryProvider(slidingSyncListProxy: allRoomsListProxy, allRoomsSummaryProvider = RoomSummaryProvider(slidingSyncListProxy: allRoomsListProxy,
eventStringBuilder: RoomEventStringBuilder(stateEventStringBuilder: RoomStateEventStringBuilder(userID: userID))) eventStringBuilder: RoomEventStringBuilder(stateEventStringBuilder: RoomStateEventStringBuilder(userID: userID)),
name: allRoomsListProxy.name)
invitesSummaryProvider = RoomSummaryProvider(slidingSyncListProxy: invitesListProxy, invitesSummaryProvider = RoomSummaryProvider(slidingSyncListProxy: invitesListProxy,
eventStringBuilder: RoomEventStringBuilder(stateEventStringBuilder: RoomStateEventStringBuilder(userID: userID))) eventStringBuilder: RoomEventStringBuilder(stateEventStringBuilder: RoomStateEventStringBuilder(userID: userID)),
name: invitesListProxy.name)
} }
private lazy var slidingSyncRequiredState = [RequiredState(key: "m.room.avatar", value: ""), private lazy var slidingSyncRequiredState = [RequiredState(key: "m.room.avatar", value: ""),
@@ -57,7 +57,7 @@ private class SlidingSyncListObserver: SlidingSyncListRoomListObserver, SlidingS
} }
class SlidingSyncListProxy: SlidingSyncListOnceBuilt { class SlidingSyncListProxy: SlidingSyncListOnceBuilt {
private let name: String let name: String
private var slidingSync: SlidingSyncProtocol? private var slidingSync: SlidingSyncProtocol?
private var slidingSyncList: SlidingSyncListProtocol? private var slidingSyncList: SlidingSyncListProtocol?
@@ -22,6 +22,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
private let slidingSyncListProxy: SlidingSyncListProxy private let slidingSyncListProxy: SlidingSyncListProxy
private let serialDispatchQueue: DispatchQueue private let serialDispatchQueue: DispatchQueue
private let eventStringBuilder: RoomEventStringBuilder private let eventStringBuilder: RoomEventStringBuilder
private let name: String
private var cancellables = Set<AnyCancellable>() private var cancellables = Set<AnyCancellable>()
@@ -47,10 +48,11 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
} }
} }
init(slidingSyncListProxy: SlidingSyncListProxy, eventStringBuilder: RoomEventStringBuilder) { init(slidingSyncListProxy: SlidingSyncListProxy, eventStringBuilder: RoomEventStringBuilder, name: String) {
self.slidingSyncListProxy = slidingSyncListProxy self.slidingSyncListProxy = slidingSyncListProxy
serialDispatchQueue = DispatchQueue(label: "io.element.elementx.roomsummaryprovider", qos: .utility) serialDispatchQueue = DispatchQueue(label: "io.element.elementx.roomsummaryprovider", qos: .utility)
self.eventStringBuilder = eventStringBuilder self.eventStringBuilder = eventStringBuilder
self.name = name
rooms = slidingSyncListProxy.currentRoomsList().map { roomListEntry in rooms = slidingSyncListProxy.currentRoomsList().map { roomListEntry in
buildSummaryForRoomListEntry(roomListEntry) buildSummaryForRoomListEntry(roomListEntry)
@@ -80,23 +82,23 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
// MARK: - Private // MARK: - Private
fileprivate func updateRoomsWithDiffs(_ diffs: [SlidingSyncListRoomsListDiff]) { fileprivate func updateRoomsWithDiffs(_ diffs: [SlidingSyncListRoomsListDiff]) {
let span = MXLog.createSpan("process_room_list_diffs") let span = MXLog.createSpan("\(name).process_room_list_diffs")
span.enter() span.enter()
defer { defer {
span.exit() span.exit()
} }
MXLog.info("Received \(diffs.count) diffs, current room list \(rooms.compactMap { $0.id ?? "Empty" })") MXLog.info("\(name): Received \(diffs.count) diffs, current room list \(rooms.compactMap { $0.id ?? "Empty" })")
rooms = diffs rooms = diffs
.reduce(rooms) { currentItems, diff in .reduce(rooms) { currentItems, diff in
guard let collectionDiff = buildDiff(from: diff, on: currentItems) else { guard let collectionDiff = buildDiff(from: diff, on: currentItems) else {
MXLog.error("Failed building CollectionDifference from \(diff)") MXLog.error("\(name): Failed building CollectionDifference from \(diff)")
return currentItems return currentItems
} }
guard let updatedItems = currentItems.applying(collectionDiff) else { guard let updatedItems = currentItems.applying(collectionDiff) else {
MXLog.error("Failed applying diff: \(collectionDiff)") MXLog.error("\(name): Failed applying diff: \(collectionDiff)")
return currentItems return currentItems
} }
@@ -105,12 +107,12 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
detectDuplicatesInRoomList(rooms) detectDuplicatesInRoomList(rooms)
MXLog.info("Finished applying \(diffs.count) diffs, new room list \(rooms.compactMap { $0.id ?? "Empty" })") MXLog.info("\(name): Finished applying \(diffs.count) diffs, new room list \(rooms.compactMap { $0.id ?? "Empty" })")
} }
private func buildRoomSummaryForIdentifier(_ identifier: String, invalidated: Bool) -> RoomSummary { private func buildRoomSummaryForIdentifier(_ identifier: String, invalidated: Bool) -> RoomSummary {
guard let room = try? slidingSyncListProxy.roomForIdentifier(identifier) else { guard let room = try? slidingSyncListProxy.roomForIdentifier(identifier) else {
MXLog.error("Failed finding room with id: \(identifier)") MXLog.error("\(name): Failed finding room with id: \(identifier)")
return .empty return .empty
} }
@@ -160,36 +162,36 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
switch diff { switch diff {
case .pushFront(let value): case .pushFront(let value):
MXLog.info("Push Front \(value.debugIdentifier)") MXLog.info("\(name): Push Front \(value.debugIdentifier)")
let summary = buildSummaryForRoomListEntry(value) let summary = buildSummaryForRoomListEntry(value)
changes.append(.insert(offset: 0, element: summary, associatedWith: nil)) changes.append(.insert(offset: 0, element: summary, associatedWith: nil))
case .pushBack(let value): case .pushBack(let value):
MXLog.info("Push Back \(value.debugIdentifier)") MXLog.info("\(name): Push Back \(value.debugIdentifier)")
let summary = buildSummaryForRoomListEntry(value) let summary = buildSummaryForRoomListEntry(value)
changes.append(.insert(offset: rooms.count, element: summary, associatedWith: nil)) changes.append(.insert(offset: rooms.count, element: summary, associatedWith: nil))
case .append(values: let values): case .append(values: let values):
let debugIdentifiers = values.map(\.debugIdentifier) let debugIdentifiers = values.map(\.debugIdentifier)
MXLog.info("Append \(debugIdentifiers)") MXLog.info("\(name): Append \(debugIdentifiers)")
for (index, value) in values.enumerated() { for (index, value) in values.enumerated() {
let summary = buildSummaryForRoomListEntry(value) let summary = buildSummaryForRoomListEntry(value)
changes.append(.insert(offset: rooms.count + index, element: summary, associatedWith: nil)) changes.append(.insert(offset: rooms.count + index, element: summary, associatedWith: nil))
} }
case .set(let index, let value): case .set(let index, let value):
MXLog.info("Update \(value.debugIdentifier) at \(index)") MXLog.info("\(name): Update \(value.debugIdentifier) at \(index)")
let summary = buildSummaryForRoomListEntry(value) let summary = buildSummaryForRoomListEntry(value)
changes.append(.remove(offset: Int(index), element: summary, associatedWith: nil)) changes.append(.remove(offset: Int(index), element: summary, associatedWith: nil))
changes.append(.insert(offset: Int(index), element: summary, associatedWith: nil)) changes.append(.insert(offset: Int(index), element: summary, associatedWith: nil))
case .insert(let index, let value): case .insert(let index, let value):
MXLog.info("Insert at \(value.debugIdentifier) at \(index)") MXLog.info("\(name): Insert at \(value.debugIdentifier) at \(index)")
let summary = buildSummaryForRoomListEntry(value) let summary = buildSummaryForRoomListEntry(value)
changes.append(.insert(offset: Int(index), element: summary, associatedWith: nil)) changes.append(.insert(offset: Int(index), element: summary, associatedWith: nil))
case .remove(let index): case .remove(let index):
let summary = rooms[Int(index)] let summary = rooms[Int(index)]
MXLog.info("Remove \(summary.id ?? "") from \(index)") MXLog.info("\(name): Remove \(summary.id ?? "") from \(index)")
changes.append(.remove(offset: Int(index), element: summary, associatedWith: nil)) changes.append(.remove(offset: Int(index), element: summary, associatedWith: nil))
case .reset(let values): case .reset(let values):
let debugIdentifiers = values.map(\.debugIdentifier) let debugIdentifiers = values.map(\.debugIdentifier)
MXLog.info("Replace all items with \(debugIdentifiers)") MXLog.info("\(name): Replace all items with \(debugIdentifiers)")
for (index, summary) in rooms.enumerated() { for (index, summary) in rooms.enumerated() {
changes.append(.remove(offset: index, element: summary, associatedWith: nil)) changes.append(.remove(offset: index, element: summary, associatedWith: nil))
} }
@@ -198,16 +200,16 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
changes.append(.insert(offset: index, element: buildSummaryForRoomListEntry(value), associatedWith: nil)) changes.append(.insert(offset: index, element: buildSummaryForRoomListEntry(value), associatedWith: nil))
} }
case .clear: case .clear:
MXLog.info("Clear all items") MXLog.info("\(name): Clear all items")
for (index, value) in rooms.enumerated() { for (index, value) in rooms.enumerated() {
changes.append(.remove(offset: index, element: value, associatedWith: nil)) changes.append(.remove(offset: index, element: value, associatedWith: nil))
} }
case .popFront: case .popFront:
MXLog.info("Pop Front") MXLog.info("\(name): Pop Front")
let summary = rooms[0] let summary = rooms[0]
changes.append(.remove(offset: 0, element: summary, associatedWith: nil)) changes.append(.remove(offset: 0, element: summary, associatedWith: nil))
case .popBack: case .popBack:
MXLog.info("Pop Back") MXLog.info("\(name): Pop Back")
guard let value = rooms.last else { guard let value = rooms.last else {
fatalError() fatalError()
} }
@@ -233,7 +235,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
let duplicates = groupedRooms.filter { $1.count > 1 } let duplicates = groupedRooms.filter { $1.count > 1 }
if duplicates.count > 0 { if duplicates.count > 0 {
MXLog.error("Found duplicated room room list items: \(duplicates)") MXLog.error("\(name): Found duplicated room room list items: \(duplicates)")
} }
} }
} }