Skip to content

Commit

Permalink
(#935) Add "On Deck" carousel section
Browse files Browse the repository at this point in the history
And fix lastread sort it was a bit effed
  • Loading branch information
Difegue committed Jun 2, 2024
1 parent 9a20b9e commit 90b3ada
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
23 changes: 15 additions & 8 deletions lib/LANraragi/Model/Search.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -408,27 +409,33 @@ 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.
if ( $sortkey eq "lastread" ) {
%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/;

# 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;
Expand Down
1 change: 0 additions & 1 deletion lib/LANraragi/Utils/Database.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 } );
}
Expand Down
11 changes: 8 additions & 3 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" },
},
}),
});
Expand Down Expand Up @@ -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???");
Expand Down

0 comments on commit 90b3ada

Please sign in to comment.