From 22c29fe936681b8cad141482dbfc001c43a7f82e Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Mon, 17 May 2021 13:05:22 -0700 Subject: [PATCH] Fix race condition in generating next/previous page references when using transparent mode. (#1456) --- components/library/src/library.rs | 56 ++++++++++++++++++------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/components/library/src/library.rs b/components/library/src/library.rs index 0a76952b..02ec3600 100644 --- a/components/library/src/library.rs +++ b/components/library/src/library.rs @@ -313,32 +313,42 @@ impl Library { } for (key, (sorted, cannot_be_sorted, sort_by)) in updates { - // Find sibling between sorted pages first - let with_siblings = find_siblings(&sorted); + let section_is_transparent = if let Some(section) = self.sections.get(key) { + section.meta.transparent + } else { + false + }; - for (k2, val1, val2) in with_siblings { - if let Some(page) = self.pages.get_mut(k2) { - match sort_by { - SortBy::Date => { - page.earlier = val2; - page.later = val1; + if !section_is_transparent { + // Find sibling between sorted pages first + let with_siblings = find_siblings(&sorted); + + for (k2, val1, val2) in with_siblings { + if let Some(page) = self.pages.get_mut(k2) { + match sort_by { + SortBy::Date => { + page.earlier = val2; + page.later = val1; + } + SortBy::UpdateDate => { + page.earlier_updated = val2; + page.later_updated = val1; + } + SortBy::Title => { + page.title_prev = val1; + page.title_next = val2; + } + SortBy::Weight => { + page.lighter = val1; + page.heavier = val2; + } + SortBy::None => { + unreachable!("Impossible to find siblings in SortBy::None") + } } - SortBy::UpdateDate => { - page.earlier_updated = val2; - page.later_updated = val1; - } - SortBy::Title => { - page.title_prev = val1; - page.title_next = val2; - } - SortBy::Weight => { - page.lighter = val1; - page.heavier = val2; - } - SortBy::None => unreachable!("Impossible to find siblings in SortBy::None"), + } else { + unreachable!("Sorting got an unknown page") } - } else { - unreachable!("Sorting got an unknown page") } }