diff --git a/lib/LANraragi/Model/Search.pm b/lib/LANraragi/Model/Search.pm index 595e55f03..f2294b83b 100644 --- a/lib/LANraragi/Model/Search.pm +++ b/lib/LANraragi/Model/Search.pm @@ -40,8 +40,9 @@ sub do_search { my $cachekey_inv = redis_encode("$category_id-$filter-$sortkey-$sortorder_inv-$newonly-$untaggedonly"); my ( $cachehit, @filtered ) = check_cache( $cachekey, $cachekey_inv ); - unless ($cachehit) { - $logger->debug("No cache available, doing a full DB parse."); + # Don't use cache for history searches since setting lastreadtime doesn't (and shouldn't) cachebust + unless ( $cachehit && $sortkey ne "lastread" ) { + $logger->debug("No cache available (or history-sorted search), doing a full DB parse."); @filtered = search_uncached( $category_id, $filter, $sortkey, $sortorder, $newonly, $untaggedonly ); # Cache this query in the search database @@ -408,6 +409,7 @@ sub sort_results { my $redis = LANraragi::Model::Config->get_redis; my %tmpfilter = (); + my @sorted = (); # Map our archives to a hash, where the key is the ID and the value is what we want to sort by. # For lastreadtime, we just get the value directly. @@ -415,7 +417,11 @@ sub sort_results { %tmpfilter = map { $_ => $redis->hget( $_, "lastreadtime" ) } @filtered; # Invert sort order for lastreadtime, biggest timestamps come first - $sortorder = !$sortorder; + @sorted = map { $_->[0] } # Map back to only having the ID + sort { $b->[1] <=> $a->[1] } # Sort by the timestamp + grep { defined $_->[1] && $_->[1] > 0 } # Remove nil timestamps + map { [ $_, $tmpfilter{$_} ] } # Map to an array containing the ID and the timestamp + @filtered; # List of IDs } else { my $re = qr/$sortkey/; @@ -423,12 +429,13 @@ sub sort_results { # For other tags, we use the first tag we found that matches the sortkey/namespace. # (If no tag, defaults to "zzzz") %tmpfilter = map { $_ => ( $redis->hget( $_, "tags" ) =~ m/.*${re}:(.*)(\,.*|$)/ ) ? $1 : "zzzz" } @filtered; - } - my @sorted = map { $_->[0] } # Map back to only having the ID - sort { ncmp( $a->[1], $b->[1] ) } # Sort by the tag - map { [ $_, lc( $tmpfilter{$_} ) ] } # Map to an array containing the ID and the lowercased tag - keys %tmpfilter; # List of IDs + # Read comments from the bottom up for a better understanding of this sort algorithm. + @sorted = map { $_->[0] } # Map back to only having the ID + sort { ncmp( $a->[1], $b->[1] ) } # Sort by the tag + map { [ $_, lc( $tmpfilter{$_} ) ] } # Map to an array containing the ID and the lowercased tag + @filtered; # List of IDs + } if ($sortorder) { @sorted = reverse @sorted; diff --git a/lib/LANraragi/Utils/Database.pm b/lib/LANraragi/Utils/Database.pm index 7cb7fe825..ccad444bf 100644 --- a/lib/LANraragi/Utils/Database.pm +++ b/lib/LANraragi/Utils/Database.pm @@ -507,7 +507,6 @@ sub invalidate_cache ( $rebuild_indexes = 0 ) { $redis->hset( "LRR_SEARCHCACHE", "created", time ); $redis->quit(); - # Re-warm the cache to ensure sufficient speed on the main index if ($rebuild_indexes) { LANraragi::Model::Config->get_minion->enqueue( build_stat_hashes => [] => { priority => 3 } ); } diff --git a/public/js/index.js b/public/js/index.js index b986f6689..84d758283 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -46,9 +46,9 @@ Index.initializeAll = function () { localStorage.customColumn2 = "series"; } - // Default to randomly picked for carousel + // Default to on deck for carousel if (localStorage.getItem("carouselType") === null) { - localStorage.carouselType = "random"; + localStorage.carouselType = "ondeck"; } // Default to opened carousel @@ -74,10 +74,10 @@ Index.initializeAll = function () { Index.updateCarousel(); }, items: { + ondeck: { name: "On Deck", icon: "fas fa-book-reader" }, random: { name: "Randomly Picked", icon: "fas fa-random" }, inbox: { name: "New Archives", icon: "fas fa-envelope-open-text" }, untagged: { name: "Untagged Archives", icon: "fas fa-edit" }, - // ondeck: { name: "On Deck", icon: "fas fa-book-reader" }, }, }), }); @@ -335,6 +335,11 @@ Index.updateCarousel = function (e) { $("#carousel-title").text("Untagged Archives"); endpoint = `/api/search?filter=${IndexTable.currentSearch}&category=${Index.selectedCategory}&untaggedonly=true&sortby=date_added&order=desc&start=-1`; break; + case "ondeck": + $("#carousel-icon")[0].classList = "fas fa-book-reader"; + $("#carousel-title").text("On Deck"); + endpoint = `/api/search?filter=${IndexTable.currentSearch}&sortby=lastread`; + break; default: $("#carousel-icon")[0].classList = "fas fa-pastafarianism"; $("#carousel-title").text("What???");