Skip to content
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 1 commit into from
Sep 13, 2024

Conversation

qstokkink
Copy link
Contributor

@qstokkink qstokkink commented Sep 13, 2024

This PR:

  • Fixes no popular torrents appearing.

In the old code, the health_list was filled with results but the pony_query = pony_query.where(lambda g: g.health in health_list) refused to link the metadata with the health info.

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
"""
)
Copy link
Contributor Author

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 qstokkink changed the title WIP: Fixed empty popular torrents page READY: Fixed empty popular torrents page Sep 13, 2024
@qstokkink qstokkink marked this pull request as ready for review September 13, 2024 09:49
@qstokkink qstokkink changed the title READY: Fixed empty popular torrents page Fixed empty popular torrents page Sep 13, 2024
@qstokkink qstokkink merged commit 79a1509 into Tribler:main Sep 13, 2024
7 checks passed
@qstokkink qstokkink deleted the fix_empty_popular_torrents branch September 13, 2024 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants