Skip to content

Commit

Permalink
Merge pull request Tribler#72 from egbertbouman/fix_search
Browse files Browse the repository at this point in the history
Fix search result errors
  • Loading branch information
egbertbouman authored Jun 14, 2024
2 parents 632ba78 + 024d61f commit 8957694
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/tribler/core/database/restapi/database_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def search_db() -> tuple[list[dict], int, int]:
if self.download_manager is not None:
self.download_manager.notifier.notify(Notification.local_query_results, data={
"query": request.query.get("fts_text"),
"results": list(pony_query)
"results": list(search_results)
})
return search_results, total, max_rowid

Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/user_activity/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def on_query_results(self, data: dict) -> None:
if query is None:
return

results = {tmd.infohash for tmd in data["results"]}
results = {tmd["infohash"] for tmd in data["results"]}
for infohash in results:
self.infohash_to_queries[infohash].append(query)
self.queries[query] = results | self.queries.get(query, set())
Expand Down
22 changes: 6 additions & 16 deletions src/tribler/test_unit/core/user_activity/test_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from asyncio import sleep
from binascii import hexlify
from dataclasses import dataclass
from unittest.mock import Mock, call

from ipv8.taskmanager import TaskManager
Expand All @@ -11,15 +10,6 @@
from tribler.core.user_activity.types import InfoHash


@dataclass(unsafe_hash=True)
class TorrentMetadata:
"""
A mocked torrent metadata class.
"""

infohash: InfoHash


class TestUserActivityManager(TestBase):
"""
Tests for the UserActivityManager class.
Expand Down Expand Up @@ -51,7 +41,7 @@ async def test_notify_local_query_empty(self) -> None:
Test that local query notifications without a query get ignored.
"""
fake_infohashes = [InfoHash(bytes([i]) * 20) for i in range(2)]
fake_torrent_metadata = [TorrentMetadata(fake_infohashes[i]) for i in range(2)]
fake_torrent_metadata = [{"infohash": fake_infohashes[i]} for i in range(2)]
fake_query = None

self.session.notifier.notify(Notification.local_query_results,
Expand All @@ -69,7 +59,7 @@ async def test_notify_remote_query_empty(self) -> None:
Test that remote query notifications without a query get ignored.
"""
fake_infohashes = [InfoHash(bytes([i]) * 20) for i in range(2)]
fake_torrent_metadata = [TorrentMetadata(fake_infohashes[i]) for i in range(2)]
fake_torrent_metadata = [{"infohash": fake_infohashes[i]} for i in range(2)]
fake_query = None

self.session.notifier.notify(Notification.remote_query_results,
Expand All @@ -87,7 +77,7 @@ async def test_notify_local_query_results(self) -> None:
Test that local query notifications get processed correctly.
"""
fake_infohashes = [InfoHash(bytes([i]) * 20) for i in range(2)]
fake_torrent_metadata = [TorrentMetadata(fake_infohashes[i]) for i in range(2)]
fake_torrent_metadata = [{"infohash": fake_infohashes[i]} for i in range(2)]
fake_query = "test query"

self.session.notifier.notify(Notification.local_query_results,
Expand All @@ -105,7 +95,7 @@ async def test_notify_remote_query_results(self) -> None:
Test that remote query notifications get processed correctly.
"""
fake_infohashes = [InfoHash(bytes([i]) * 20) for i in range(2)]
fake_torrent_metadata = [TorrentMetadata(fake_infohashes[i]) for i in range(2)]
fake_torrent_metadata = [{"infohash": fake_infohashes[i]} for i in range(2)]
fake_query = "test query"

self.session.notifier.notify(Notification.remote_query_results,
Expand All @@ -126,7 +116,7 @@ async def test_notify_local_query_results_overflow(self) -> None:
self.manager.max_query_history = 1

fake_infohashes = [InfoHash(bytes([i]) * 20) for i in range(2)]
fake_torrent_metadata = [TorrentMetadata(fake_infohashes[i]) for i in range(2)]
fake_torrent_metadata = [{"infohash": fake_infohashes[i]} for i in range(2)]
fake_query_1 = "test query 1"
fake_query_2 = "test query 2"

Expand Down Expand Up @@ -154,7 +144,7 @@ async def test_notify_remote_query_results_overflow(self) -> None:
self.manager.max_query_history = 1

fake_infohashes = [InfoHash(bytes([i]) * 20) for i in range(2)]
fake_torrent_metadata = [TorrentMetadata(fake_infohashes[i]) for i in range(2)]
fake_torrent_metadata = [{"infohash": fake_infohashes[i]} for i in range(2)]
fake_query_1 = "test query 1"
fake_query_2 = "test query 2"

Expand Down

0 comments on commit 8957694

Please sign in to comment.