diff --git a/Tribler/Core/CacheDB/SqliteCacheDBHandler.py b/Tribler/Core/CacheDB/SqliteCacheDBHandler.py index 8330aa7d48b..d0a2f68e371 100644 --- a/Tribler/Core/CacheDB/SqliteCacheDBHandler.py +++ b/Tribler/Core/CacheDB/SqliteCacheDBHandler.py @@ -2365,7 +2365,7 @@ def calculate_score_channel(keywords, channel_name, channel_description): # and 20% on the matching in the channel description. return 0.8 * scores[0] + 0.2 * scores[1] - def search_in_local_channels_db(self, query, first=0, last=None, count=False): + def search_in_local_channels_db(self, query, first=0, last=None, count=False, chan_size_limit=3): """ Searches for matching channels against a given query in the database. """ @@ -2376,7 +2376,10 @@ def search_in_local_channels_db(self, query, first=0, last=None, count=False): else: sql = "SELECT id, dispersy_cid, name, description, nr_torrents, nr_favorite, nr_spam, modified " - sql +="FROM Channels WHERE nr_torrents > 2 and (" + sql +="FROM Channels WHERE" + if chan_size_limit: + sql += " nr_torrents >= %i and " % chan_size_limit + sql += " (" for _ in xrange(len(keywords)): sql += " name LIKE ? OR description LIKE ? OR " sql = sql[:-4] + " )" diff --git a/Tribler/Test/Core/CreditMining/test_credit_mining_sources.py b/Tribler/Test/Core/CreditMining/test_credit_mining_sources.py index 531619d5d81..99ef856bac8 100644 --- a/Tribler/Test/Core/CreditMining/test_credit_mining_sources.py +++ b/Tribler/Test/Core/CreditMining/test_credit_mining_sources.py @@ -57,24 +57,6 @@ def test_existing_channel_lookup(self): self.assertEqual(source.community, community, 'ChannelSource failed to find existing ChannelCommunity') source.stop() - @inlineCallbacks - def test_torrent_from_db(self): - # Torrent is a tuple: (channel_id, dispersy_id, peer_id, infohash, timestamp, name, files, trackers) - torrent = (0, self.cid, 42, '\00' * 20, 0, u'torrent', [], []) - channel_db_handler = self.session.open_dbhandler(NTFY_CHANNELCAST) - channel_db_handler.on_torrents_from_dispersy([torrent]) - - torrent_inserteds = [] - torrent_insert_callback = lambda source, infohash, name: torrent_inserteds.append((source, infohash, name)) - source = ChannelSource(self.session, self.cid, torrent_insert_callback) - source.start() - - yield deferLater(reactor, 1, lambda: None) - self.assertIn((self.cid, hexlify(torrent[3]), torrent[5]), torrent_inserteds, - 'ChannelSource failed to insert torrent') - - source.stop() - def test_torrent_discovered(self): torrent_inserteds = [] torrent_insert_callback = lambda source, infohash, name: torrent_inserteds.append((source, infohash, name)) diff --git a/Tribler/Test/Core/test_sqlitecachedbhandler_channels.py b/Tribler/Test/Core/test_sqlitecachedbhandler_channels.py index 862bc2cd64b..a95ceb11c18 100644 --- a/Tribler/Test/Core/test_sqlitecachedbhandler_channels.py +++ b/Tribler/Test/Core/test_sqlitecachedbhandler_channels.py @@ -57,7 +57,7 @@ def test_get_channels_by_cid(self): self.assertEqual(len(self.cdb.getChannelsByCID(["3"])), 0) def test_get_all_channels(self): - self.assertEqual(len(self.cdb.getAllChannels()), 8) + self.assertEqual(len(self.cdb.getAllChannels()), 3) def test_get_new_channels(self): self.assertEqual(len(self.cdb.getNewChannels()), 1) @@ -118,7 +118,7 @@ def test_search_local_channels(self): """ Testing whether the right results are returned when searching in the local database for channels """ - results = self.cdb.search_in_local_channels_db("fancy") + results = self.cdb.search_in_local_channels_db("fancy", chan_size_limit=None) self.assertEqual(len(results), 2) self.assertNotEqual(results[0][-1], 0.0) # Relevance score of result should not be zero diff --git a/Tribler/Test/Core/test_sqlitecachedbhandler_torrents.py b/Tribler/Test/Core/test_sqlitecachedbhandler_torrents.py index 633fb4bdf3a..ab531b60476 100644 --- a/Tribler/Test/Core/test_sqlitecachedbhandler_torrents.py +++ b/Tribler/Test/Core/test_sqlitecachedbhandler_torrents.py @@ -292,7 +292,7 @@ def test_search_local_torrents(self): """ Test the search procedure in the local database when searching for torrents """ - results = self.tdb.search_in_local_torrents_db('content', ['infohash', 'num_seeders']) + results = self.tdb.search_in_local_torrents_db('content', ['infohash', 'num_seeders'], family_filter=False, last = 5000) self.assertEqual(len(results), 4849) self.assertNotEqual(results[0][-1], 0.0) # Relevance score of result should not be zero results = self.tdb.search_in_local_torrents_db('fdsafasfds', ['infohash'])