Skip to content

Commit

Permalink
Add back verbose logging for the timeline provider to help debug the …
Browse files Browse the repository at this point in the history
…event cache and lazy loading.
  • Loading branch information
stefanceriu committed Feb 4, 2025
1 parent bad4a8f commit f0b8775
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions ElementX/Sources/Services/Timeline/TimelineProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class TimelineProvider: TimelineProviderProtocol {
span.exit()
}

MXLog.verbose("Received diffs: \(diffs)")

itemProxies = diffs.reduce(itemProxies) { currentItems, diff in
guard let collectionDiff = buildDiff(from: diff, on: currentItems) else {
MXLog.error("Failed building CollectionDifference from \(diff)")
Expand Down Expand Up @@ -222,3 +224,53 @@ private final class RoomTimelineListener: TimelineListener {
onUpdateClosure(diff)
}
}

private extension Array where Element == TimelineDiff {
var debugDescription: String {
"[" + map(\.debugDescription).joined(separator: ",") + "]"
}
}

extension TimelineDiff: @retroactive CustomDebugStringConvertible {
public var debugDescription: String {
switch change() {
case .append:
guard let update = append() else {
fatalError()
}
return "Append(\(update.count))"
case .clear:
return "Clear"
case .insert:
return "Insert"
case .set:
guard let update = set() else {
fatalError()
}
return "Set(\(update.index))"
case .remove:
guard let update = remove() else {
fatalError()
}
return "Remove(\(update)"
case .pushBack:
return "PushBack"
case .pushFront:
return "PushFront"
case .popBack:
return "PopBack"
case .popFront:
return "PopFront"
case .truncate:
guard let update = truncate() else {
fatalError()
}
return "Truncate(\(update))"
case .reset:
guard let update = reset() else {
fatalError()
}
return "Reset(\(update.count)@\(update.startIndex)-\(update.endIndex))"
}
}
}

0 comments on commit f0b8775

Please sign in to comment.