-
Notifications
You must be signed in to change notification settings - Fork 449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed empty popular torrents page #8152
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
qstokkink
force-pushed
the
fix_empty_popular_torrents
branch
from
September 13, 2024 09:45
f27200e
to
0c76f48
Compare
qstokkink
commented
Sep 13, 2024
Comment on lines
+626
to
+670
if sort_by is None and txt_filter: | ||
""" | ||
The following call of `sort_by` produces an ORDER BY expression that looks like this: | ||
|
||
ORDER BY | ||
case when "g"."metadata_type" = $CHANNEL_TORRENT then 1 | ||
when "g"."metadata_type" = $COLLECTION_NODE then 2 | ||
else 3 end, | ||
|
||
search_rank( | ||
$QUERY_STRING, | ||
g.title, | ||
torrentstate.seeders, | ||
torrentstate.leechers, | ||
$CURRENT_TIME - strftime('%s', g.torrent_date) | ||
) DESC, | ||
|
||
"torrentstate"."last_check" DESC, | ||
|
||
So, the channel torrents and channel folders are always on top if they are not filtered out. | ||
Then regular torrents are selected in order of their relevance according to a search_rank() result. | ||
If two torrents have the same search rank, they are ordered by the last time they were checked. | ||
|
||
The search_rank() function is called directly from the SQLite query, but is implemented in Python, | ||
it is actually the torrent_rank() function from core/utilities/search_utils.py, wrapped with | ||
keep_exception() to return possible exception from SQLite to Python. | ||
|
||
The search_rank() function receives the following arguments: | ||
- the current query string (like "Big Buck Bunny"); | ||
- the title of the current torrent; | ||
- the number of seeders; | ||
- the number of leechers; | ||
- the number of seconds since the torrent's creation time. | ||
""" | ||
|
||
pony_query = pony_query.sort_by( | ||
f""" | ||
(1 if g.metadata_type == {CHANNEL_TORRENT} else 2 if g.metadata_type == {COLLECTION_NODE} else 3), | ||
raw_sql('''search_rank( | ||
$txt_filter, g.title, torrentstate.seeders, torrentstate.leechers, | ||
$int(time()) - strftime('%s', g.torrent_date) | ||
) DESC'''), | ||
desc(g.health.last_check) # just to trigger the TorrentState table inclusion into the left join | ||
""" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ruff
wanted me to change the if
condition, nothing else changed.
qstokkink
changed the title
WIP: Fixed empty popular torrents page
READY: Fixed empty popular torrents page
Sep 13, 2024
egbertbouman
approved these changes
Sep 13, 2024
qstokkink
changed the title
READY: Fixed empty popular torrents page
Fixed empty popular torrents page
Sep 13, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR:
In the old code, the
health_list
was filled with results but thepony_query = pony_query.where(lambda g: g.health in health_list)
refused to link the metadata with the health info.