Skip to content

Commit e9b4605

Browse files
authored
Fix an issue with non-stable order in Posts and Pages in stats (#23915)
* Fix an issue with non-stable order in Posts and Pages in stats * Update release notes * Update release notes
1 parent a045bf1 commit e9b4605

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* [*] Add scroll-to-top button to Reader streams [#23957]
2222
* [*] Add a quick way to replace a featured image for a post [#23962]
2323
* [*] Fix an issue with posts in Reader sometimes showing incorrect covers [#23914]
24+
* [*] Fix non-stable order in Posts and Pages section in Stats [#23915]
2425

2526
25.6
2627
-----

WordPress/Classes/Stores/StatsPeriodStore.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,12 +895,24 @@ private extension StatsPeriodStore {
895895
}
896896
}
897897

898-
private func receivedPostsAndPages(_ postsAndPages: StatsTopPostsTimeIntervalData?, _ error: Error?) {
898+
private func receivedPostsAndPages(_ data: StatsTopPostsTimeIntervalData?, _ error: Error?) {
899899
transaction { state in
900900
state.topPostsAndPagesStatus = error != nil ? .error : .success
901901

902-
if postsAndPages != nil {
903-
state.topPostsAndPages = postsAndPages
902+
if let data {
903+
let sortedTopPosts = data.topPosts.sorted { lhs, rhs in
904+
if lhs.viewsCount == rhs.viewsCount {
905+
return lhs.title.localizedCaseInsensitiveCompare(rhs.title) == .orderedAscending
906+
}
907+
return lhs.viewsCount > rhs.viewsCount
908+
}
909+
state.topPostsAndPages = StatsTopPostsTimeIntervalData(
910+
period: data.period,
911+
periodEndDate: data.periodEndDate,
912+
topPosts: sortedTopPosts,
913+
totalViewsCount: data.totalViewsCount,
914+
otherViewsCount: data.otherViewsCount
915+
)
904916
}
905917
}
906918
}

0 commit comments

Comments
 (0)