diff --git a/src/tribler/core/components/conftest.py b/src/tribler/core/components/conftest.py index 35a57027b10..8da7ddace96 100644 --- a/src/tribler/core/components/conftest.py +++ b/src/tribler/core/components/conftest.py @@ -4,7 +4,7 @@ from ipv8.keyvault.private.libnaclkey import LibNaCLSK from ipv8.util import succeed -from tribler.core.components.knowledge.db.knowledge_db import KnowledgeDatabase +from tribler.core.components.database.db.knowledge_db import KnowledgeDatabase from tribler.core.components.libtorrent.download_manager.download_config import DownloadConfig from tribler.core.components.libtorrent.download_manager.download_manager import DownloadManager from tribler.core.components.libtorrent.settings import LibtorrentSettings diff --git a/src/tribler/core/components/database/__init__.py b/src/tribler/core/components/database/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler/core/components/database/database_component.py b/src/tribler/core/components/database/database_component.py new file mode 100644 index 00000000000..62b6e015d4b --- /dev/null +++ b/src/tribler/core/components/database/database_component.py @@ -0,0 +1,23 @@ +from tribler.core.components.component import Component +from tribler.core.components.database.db.knowledge_db import KnowledgeDatabase +from tribler.core.utilities.simpledefs import STATEDIR_DB_DIR + + +class DatabaseComponent(Component): + tribler_should_stop_on_component_error = True + + db: KnowledgeDatabase = None + + async def run(self): + await super().run() + + db_path = self.session.config.state_dir / STATEDIR_DB_DIR / "tribler.db" + if self.session.config.gui_test_mode: + db_path = ":memory:" + + self.db = KnowledgeDatabase(str(db_path), create_tables=True) + + async def shutdown(self): + await super().shutdown() + if self.db: + self.db.shutdown() diff --git a/src/tribler/core/components/database/db/__init__.py b/src/tribler/core/components/database/db/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler/core/components/knowledge/db/knowledge_db.py b/src/tribler/core/components/database/db/knowledge_db.py similarity index 100% rename from src/tribler/core/components/knowledge/db/knowledge_db.py rename to src/tribler/core/components/database/db/knowledge_db.py diff --git a/src/tribler/core/components/database/db/tests/__init__.py b/src/tribler/core/components/database/db/tests/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/tribler/core/components/knowledge/db/tests/test_knowledge_db.py b/src/tribler/core/components/database/db/tests/test_knowledge_db.py similarity index 99% rename from src/tribler/core/components/knowledge/db/tests/test_knowledge_db.py rename to src/tribler/core/components/database/db/tests/test_knowledge_db.py index 66716f22044..f05fd13689b 100644 --- a/src/tribler/core/components/knowledge/db/tests/test_knowledge_db.py +++ b/src/tribler/core/components/database/db/tests/test_knowledge_db.py @@ -3,9 +3,9 @@ from pony.orm import commit, db_session -from tribler.core.components.knowledge.db.knowledge_db import KnowledgeDatabase, Operation, \ +from tribler.core.components.database.db.knowledge_db import KnowledgeDatabase, Operation, \ PUBLIC_KEY_FOR_AUTO_GENERATED_OPERATIONS, ResourceType, SHOW_THRESHOLD, SimpleStatement -from tribler.core.components.knowledge.db.tests.test_knowledge_db_base import Resource, TestTagDBBase +from tribler.core.components.database.db.tests.test_knowledge_db_base import Resource, TestTagDBBase from tribler.core.utilities.pony_utils import TriblerDatabase, get_or_create diff --git a/src/tribler/core/components/knowledge/db/tests/test_knowledge_db_base.py b/src/tribler/core/components/database/db/tests/test_knowledge_db_base.py similarity index 96% rename from src/tribler/core/components/knowledge/db/tests/test_knowledge_db_base.py rename to src/tribler/core/components/database/db/tests/test_knowledge_db_base.py index f0b5755d4c1..9d7a72cc9f0 100644 --- a/src/tribler/core/components/knowledge/db/tests/test_knowledge_db_base.py +++ b/src/tribler/core/components/database/db/tests/test_knowledge_db_base.py @@ -5,7 +5,7 @@ from pony.orm import commit, db_session from tribler.core.components.knowledge.community.knowledge_payload import StatementOperation -from tribler.core.components.knowledge.db.knowledge_db import KnowledgeDatabase, Operation, ResourceType, SHOW_THRESHOLD +from tribler.core.components.database.db.knowledge_db import KnowledgeDatabase, Operation, ResourceType, SHOW_THRESHOLD from tribler.core.utilities.pony_utils import get_or_create diff --git a/src/tribler/core/components/gigachannel/gigachannel_component.py b/src/tribler/core/components/gigachannel/gigachannel_component.py index 3a5891c1c35..5534ffaffdd 100644 --- a/src/tribler/core/components/gigachannel/gigachannel_component.py +++ b/src/tribler/core/components/gigachannel/gigachannel_component.py @@ -1,6 +1,7 @@ from ipv8.peerdiscovery.network import Network from tribler.core.components.component import Component +from tribler.core.components.database.database_component import DatabaseComponent from tribler.core.components.gigachannel.community.gigachannel_community import ( GigaChannelCommunity, GigaChannelTestnetCommunity, @@ -25,7 +26,7 @@ async def run(self): self._ipv8_component = await self.require_component(Ipv8Component) metadata_store_component = await self.require_component(MetadataStoreComponent) - knowledge_component = await self.get_component(KnowledgeComponent) + db_component = await self.get_component(DatabaseComponent) giga_channel_cls = GigaChannelTestnetCommunity if config.general.testnet else GigaChannelCommunity community = giga_channel_cls( @@ -37,7 +38,7 @@ async def run(self): rqc_settings=config.remote_query_community, metadata_store=metadata_store_component.mds, max_peers=50, - knowledge_db=knowledge_component.knowledge_db if knowledge_component else None + knowledge_db=db_component.db if db_component else None ) self.community = community self._ipv8_component.initialise_community_by_default(community, default_random_walk_max_peers=30) diff --git a/src/tribler/core/components/gigachannel/tests/test_gigachannel_component.py b/src/tribler/core/components/gigachannel/tests/test_gigachannel_component.py index 90114ac8740..bd5e75b66bc 100644 --- a/src/tribler/core/components/gigachannel/tests/test_gigachannel_component.py +++ b/src/tribler/core/components/gigachannel/tests/test_gigachannel_component.py @@ -1,3 +1,4 @@ +from tribler.core.components.database.database_component import DatabaseComponent from tribler.core.components.gigachannel.gigachannel_component import GigaChannelComponent from tribler.core.components.ipv8.ipv8_component import Ipv8Component from tribler.core.components.key.key_component import KeyComponent @@ -13,7 +14,7 @@ async def test_giga_channel_component(tribler_config): tribler_config.ipv8.enabled = True tribler_config.libtorrent.enabled = True tribler_config.chant.enabled = True - components = [KnowledgeComponent(), MetadataStoreComponent(), KeyComponent(), Ipv8Component(), + components = [DatabaseComponent(), KnowledgeComponent(), MetadataStoreComponent(), KeyComponent(), Ipv8Component(), GigaChannelComponent()] async with Session(tribler_config, components) as session: comp = session.get_instance(GigaChannelComponent) diff --git a/src/tribler/core/components/gigachannel_manager/tests/test_gigachannel_manager_component.py b/src/tribler/core/components/gigachannel_manager/tests/test_gigachannel_manager_component.py index 0885d237312..78435fa18f0 100644 --- a/src/tribler/core/components/gigachannel_manager/tests/test_gigachannel_manager_component.py +++ b/src/tribler/core/components/gigachannel_manager/tests/test_gigachannel_manager_component.py @@ -1,3 +1,4 @@ +from tribler.core.components.database.database_component import DatabaseComponent from tribler.core.components.gigachannel_manager.gigachannel_manager_component import GigachannelManagerComponent from tribler.core.components.ipv8.ipv8_component import Ipv8Component from tribler.core.components.key.key_component import KeyComponent @@ -12,9 +13,8 @@ async def test_gigachannel_manager_component(tribler_config): - components = [Ipv8Component(), KnowledgeComponent(), SocksServersComponent(), KeyComponent(), - MetadataStoreComponent(), - LibtorrentComponent(), GigachannelManagerComponent()] + components = [DatabaseComponent(), Ipv8Component(), KnowledgeComponent(), SocksServersComponent(), KeyComponent(), + MetadataStoreComponent(), LibtorrentComponent(), GigachannelManagerComponent()] async with Session(tribler_config, components) as session: comp = session.get_instance(GigachannelManagerComponent) assert comp.started_event.is_set() and not comp.failed diff --git a/src/tribler/core/components/knowledge/community/knowledge_community.py b/src/tribler/core/components/knowledge/community/knowledge_community.py index 2c342ee4823..96f1ae575a7 100644 --- a/src/tribler/core/components/knowledge/community/knowledge_community.py +++ b/src/tribler/core/components/knowledge/community/knowledge_community.py @@ -18,7 +18,7 @@ from tribler.core.components.knowledge.community.knowledge_validator import validate_operation, validate_resource, \ validate_resource_type from tribler.core.components.knowledge.community.operations_requests import OperationsRequests, PeerValidationError -from tribler.core.components.knowledge.db.knowledge_db import KnowledgeDatabase +from tribler.core.components.database.db.knowledge_db import KnowledgeDatabase REQUESTED_OPERATIONS_COUNT = 10 diff --git a/src/tribler/core/components/knowledge/community/knowledge_validator.py b/src/tribler/core/components/knowledge/community/knowledge_validator.py index ff70b3bf3e9..25d5c0220d6 100644 --- a/src/tribler/core/components/knowledge/community/knowledge_validator.py +++ b/src/tribler/core/components/knowledge/community/knowledge_validator.py @@ -1,4 +1,4 @@ -from tribler.core.components.knowledge.db.knowledge_db import Operation, ResourceType +from tribler.core.components.database.db.knowledge_db import Operation, ResourceType from tribler.core.components.knowledge.knowledge_constants import MAX_RESOURCE_LENGTH, MIN_RESOURCE_LENGTH diff --git a/src/tribler/core/components/knowledge/community/tests/test_knowledge_community.py b/src/tribler/core/components/knowledge/community/tests/test_knowledge_community.py index 5833e1a265e..7e27676df5c 100644 --- a/src/tribler/core/components/knowledge/community/tests/test_knowledge_community.py +++ b/src/tribler/core/components/knowledge/community/tests/test_knowledge_community.py @@ -8,7 +8,7 @@ from tribler.core.components.knowledge.community.knowledge_community import KnowledgeCommunity from tribler.core.components.knowledge.community.knowledge_payload import StatementOperation -from tribler.core.components.knowledge.db.knowledge_db import KnowledgeDatabase, Operation, ResourceType +from tribler.core.components.database.db.knowledge_db import KnowledgeDatabase, Operation, ResourceType REQUEST_INTERVAL_FOR_RANDOM_OPERATIONS = 0.1 # in seconds diff --git a/src/tribler/core/components/knowledge/community/tests/test_knowledge_validator.py b/src/tribler/core/components/knowledge/community/tests/test_knowledge_validator.py index a4159822b05..7dc00087ca1 100644 --- a/src/tribler/core/components/knowledge/community/tests/test_knowledge_validator.py +++ b/src/tribler/core/components/knowledge/community/tests/test_knowledge_validator.py @@ -2,7 +2,7 @@ from tribler.core.components.knowledge.community.knowledge_validator import is_valid_resource, validate_operation, \ validate_resource, validate_resource_type -from tribler.core.components.knowledge.db.knowledge_db import Operation, ResourceType +from tribler.core.components.database.db.knowledge_db import Operation, ResourceType VALID_TAGS = [ 'nl', diff --git a/src/tribler/core/components/knowledge/knowledge_component.py b/src/tribler/core/components/knowledge/knowledge_component.py index d5c8d9745ec..d1cfc487853 100644 --- a/src/tribler/core/components/knowledge/knowledge_component.py +++ b/src/tribler/core/components/knowledge/knowledge_component.py @@ -1,19 +1,17 @@ import tribler.core.components.metadata_store.metadata_store_component as metadata_store_component from tribler.core.components.component import Component +from tribler.core.components.database.database_component import DatabaseComponent from tribler.core.components.ipv8.ipv8_component import Ipv8Component from tribler.core.components.key.key_component import KeyComponent from tribler.core.components.knowledge.community.knowledge_community import KnowledgeCommunity -from tribler.core.components.knowledge.db.knowledge_db import KnowledgeDatabase from tribler.core.components.knowledge.rules.knowledge_rules_processor import KnowledgeRulesProcessor from tribler.core.components.metadata_store.utils import generate_test_channels -from tribler.core.utilities.simpledefs import STATEDIR_DB_DIR class KnowledgeComponent(Component): tribler_should_stop_on_component_error = False community: KnowledgeCommunity = None - knowledge_db: KnowledgeDatabase = None rules_processor: KnowledgeRulesProcessor = None _ipv8_component: Ipv8Component = None @@ -23,22 +21,18 @@ async def run(self): self._ipv8_component = await self.require_component(Ipv8Component) key_component = await self.require_component(KeyComponent) mds_component = await self.require_component(metadata_store_component.MetadataStoreComponent) + db_component = await self.require_component(DatabaseComponent) - db_path = self.session.config.state_dir / STATEDIR_DB_DIR / "knowledge.db" - if self.session.config.gui_test_mode: - db_path = ":memory:" - - self.knowledge_db = KnowledgeDatabase(str(db_path), create_tables=True) self.community = KnowledgeCommunity( self._ipv8_component.peer, self._ipv8_component.ipv8.endpoint, self._ipv8_component.ipv8.network, - db=self.knowledge_db, + db=db_component.db, key=key_component.secondary_key ) self.rules_processor = KnowledgeRulesProcessor( notifier=self.session.notifier, - db=self.knowledge_db, + db=db_component.db, mds=mds_component.mds, ) self.rules_processor.start() @@ -46,7 +40,7 @@ async def run(self): self._ipv8_component.initialise_community_by_default(self.community) if self.session.config.gui_test_mode: - generate_test_channels(mds_component.mds, self.knowledge_db) + generate_test_channels(mds_component.mds, db_component.db) async def shutdown(self): await super().shutdown() @@ -54,5 +48,3 @@ async def shutdown(self): await self._ipv8_component.unload_community(self.community) if self.rules_processor: await self.rules_processor.shutdown() - if self.knowledge_db: - self.knowledge_db.shutdown() diff --git a/src/tribler/core/components/knowledge/restapi/knowledge_endpoint.py b/src/tribler/core/components/knowledge/restapi/knowledge_endpoint.py index af73460657f..270068b060b 100644 --- a/src/tribler/core/components/knowledge/restapi/knowledge_endpoint.py +++ b/src/tribler/core/components/knowledge/restapi/knowledge_endpoint.py @@ -10,7 +10,7 @@ from tribler.core.components.knowledge.community.knowledge_community import KnowledgeCommunity from tribler.core.components.knowledge.community.knowledge_payload import StatementOperation from tribler.core.components.knowledge.community.knowledge_validator import is_valid_resource -from tribler.core.components.knowledge.db.knowledge_db import KnowledgeDatabase, Operation, ResourceType +from tribler.core.components.database.db.knowledge_db import KnowledgeDatabase, Operation, ResourceType from tribler.core.components.restapi.rest.rest_endpoint import HTTP_BAD_REQUEST, RESTEndpoint, RESTResponse from tribler.core.components.restapi.rest.schema import HandledErrorSchema from tribler.core.utilities.utilities import froze_it diff --git a/src/tribler/core/components/knowledge/restapi/tests/test_knowledge_endpoint.py b/src/tribler/core/components/knowledge/restapi/tests/test_knowledge_endpoint.py index ed984168e5a..6de2af0d311 100644 --- a/src/tribler/core/components/knowledge/restapi/tests/test_knowledge_endpoint.py +++ b/src/tribler/core/components/knowledge/restapi/tests/test_knowledge_endpoint.py @@ -7,7 +7,7 @@ from tribler.core.components.conftest import TEST_PERSONAL_KEY from tribler.core.components.knowledge.community.knowledge_payload import StatementOperation -from tribler.core.components.knowledge.db.knowledge_db import Operation, ResourceType +from tribler.core.components.database.db.knowledge_db import Operation, ResourceType from tribler.core.components.knowledge.restapi.knowledge_endpoint import KnowledgeEndpoint from tribler.core.components.restapi.rest.base_api_test import do_request from tribler.core.utilities.date_utils import freeze_time diff --git a/src/tribler/core/components/knowledge/rules/knowledge_rules_processor.py b/src/tribler/core/components/knowledge/rules/knowledge_rules_processor.py index a53683ab010..ca72213d37a 100644 --- a/src/tribler/core/components/knowledge/rules/knowledge_rules_processor.py +++ b/src/tribler/core/components/knowledge/rules/knowledge_rules_processor.py @@ -10,7 +10,7 @@ from pony.orm import db_session from tribler.core import notifications -from tribler.core.components.knowledge.db.knowledge_db import KnowledgeDatabase, ResourceType +from tribler.core.components.database.db.knowledge_db import KnowledgeDatabase, ResourceType from tribler.core.components.knowledge.rules.rules_content_items import content_items_rules from tribler.core.components.knowledge.rules.rules_general_tags import general_rules from tribler.core.components.knowledge.rules.tag_rules_base import extract_only_valid_tags diff --git a/src/tribler/core/components/knowledge/rules/tests/test_knowledge_rules_processor.py b/src/tribler/core/components/knowledge/rules/tests/test_knowledge_rules_processor.py index aa24e3d884d..5d4e9fec256 100644 --- a/src/tribler/core/components/knowledge/rules/tests/test_knowledge_rules_processor.py +++ b/src/tribler/core/components/knowledge/rules/tests/test_knowledge_rules_processor.py @@ -5,7 +5,7 @@ from ipv8.keyvault.private.libnaclkey import LibNaCLSK from pony.orm import db_session -from tribler.core.components.knowledge.db.knowledge_db import KnowledgeDatabase, ResourceType +from tribler.core.components.database.db.knowledge_db import KnowledgeDatabase, ResourceType from tribler.core.components.knowledge.rules.knowledge_rules_processor import KnowledgeRulesProcessor from tribler.core.components.metadata_store.db.serialization import REGULAR_TORRENT from tribler.core.components.metadata_store.db.store import MetadataStore diff --git a/src/tribler/core/components/knowledge/tests/test_knowledge_component.py b/src/tribler/core/components/knowledge/tests/test_knowledge_component.py index 046af11743e..d0568b100ac 100644 --- a/src/tribler/core/components/knowledge/tests/test_knowledge_component.py +++ b/src/tribler/core/components/knowledge/tests/test_knowledge_component.py @@ -1,3 +1,4 @@ +from tribler.core.components.database.database_component import DatabaseComponent from tribler.core.components.ipv8.ipv8_component import Ipv8Component from tribler.core.components.key.key_component import KeyComponent from tribler.core.components.knowledge.knowledge_component import KnowledgeComponent @@ -9,7 +10,7 @@ async def test_tag_component(tribler_config): - components = [MetadataStoreComponent(), KeyComponent(), Ipv8Component(), KnowledgeComponent()] + components = [DatabaseComponent(), MetadataStoreComponent(), KeyComponent(), Ipv8Component(), KnowledgeComponent()] async with Session(tribler_config, components) as session: comp = session.get_instance(KnowledgeComponent) assert comp.started_event.is_set() and not comp.failed diff --git a/src/tribler/core/components/metadata_store/remote_query_community/remote_query_community.py b/src/tribler/core/components/metadata_store/remote_query_community/remote_query_community.py index b0179e00a7b..e7c9e4dd6e8 100644 --- a/src/tribler/core/components/metadata_store/remote_query_community/remote_query_community.py +++ b/src/tribler/core/components/metadata_store/remote_query_community/remote_query_community.py @@ -16,7 +16,7 @@ from tribler.core.components.ipv8.eva.result import TransferResult from tribler.core.components.ipv8.tribler_community import TriblerCommunity from tribler.core.components.knowledge.community.knowledge_validator import is_valid_resource -from tribler.core.components.knowledge.db.knowledge_db import ResourceType +from tribler.core.components.database.db.knowledge_db import ResourceType from tribler.core.components.metadata_store.db.orm_bindings.channel_metadata import LZ4_EMPTY_ARCHIVE, entries_to_chunk from tribler.core.components.metadata_store.db.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT from tribler.core.components.metadata_store.db.store import MetadataStore diff --git a/src/tribler/core/components/metadata_store/remote_query_community/tests/test_remote_search_by_tags.py b/src/tribler/core/components/metadata_store/remote_query_community/tests/test_remote_search_by_tags.py index a15ff9a35f2..a9b496c008b 100644 --- a/src/tribler/core/components/metadata_store/remote_query_community/tests/test_remote_search_by_tags.py +++ b/src/tribler/core/components/metadata_store/remote_query_community/tests/test_remote_search_by_tags.py @@ -5,8 +5,8 @@ from ipv8.test.base import TestBase from pony.orm import db_session -from tribler.core.components.knowledge.db.knowledge_db import KnowledgeDatabase, ResourceType, SHOW_THRESHOLD -from tribler.core.components.knowledge.db.tests.test_knowledge_db import Resource, TestTagDB +from tribler.core.components.database.db.knowledge_db import KnowledgeDatabase, ResourceType, SHOW_THRESHOLD +from tribler.core.components.database.db.tests.test_knowledge_db import Resource, TestTagDB from tribler.core.components.metadata_store.db.orm_bindings.channel_node import NEW from tribler.core.components.metadata_store.db.store import MetadataStore from tribler.core.components.metadata_store.remote_query_community.remote_query_community import RemoteQueryCommunity diff --git a/src/tribler/core/components/metadata_store/restapi/metadata_endpoint_base.py b/src/tribler/core/components/metadata_store/restapi/metadata_endpoint_base.py index 6a9d2879b41..0a0b8029eb2 100644 --- a/src/tribler/core/components/metadata_store/restapi/metadata_endpoint_base.py +++ b/src/tribler/core/components/metadata_store/restapi/metadata_endpoint_base.py @@ -3,7 +3,7 @@ from pony.orm import db_session -from tribler.core.components.knowledge.db.knowledge_db import KnowledgeDatabase, ResourceType +from tribler.core.components.database.db.knowledge_db import KnowledgeDatabase, ResourceType from tribler.core.components.knowledge.rules.knowledge_rules_processor import KnowledgeRulesProcessor from tribler.core.components.metadata_store.category_filter.family_filter import default_xxx_filter from tribler.core.components.metadata_store.db.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT diff --git a/src/tribler/core/components/metadata_store/restapi/search_endpoint.py b/src/tribler/core/components/metadata_store/restapi/search_endpoint.py index 26dc941e265..2bf5103dd98 100644 --- a/src/tribler/core/components/metadata_store/restapi/search_endpoint.py +++ b/src/tribler/core/components/metadata_store/restapi/search_endpoint.py @@ -8,7 +8,7 @@ from marshmallow.fields import Integer, String from pony.orm import db_session -from tribler.core.components.knowledge.db.knowledge_db import ResourceType +from tribler.core.components.database.db.knowledge_db import ResourceType from tribler.core.components.metadata_store.db.serialization import SNIPPET from tribler.core.components.metadata_store.db.store import MetadataStore from tribler.core.components.metadata_store.restapi.metadata_endpoint import MetadataEndpointBase diff --git a/src/tribler/core/components/metadata_store/restapi/tests/test_channels_endpoint.py b/src/tribler/core/components/metadata_store/restapi/tests/test_channels_endpoint.py index 4b16b29a9b0..7e200cc66f1 100644 --- a/src/tribler/core/components/metadata_store/restapi/tests/test_channels_endpoint.py +++ b/src/tribler/core/components/metadata_store/restapi/tests/test_channels_endpoint.py @@ -8,7 +8,7 @@ from pony.orm import db_session from tribler.core.components.gigachannel.community.gigachannel_community import NoChannelSourcesException -from tribler.core.components.knowledge.db.knowledge_db import ResourceType +from tribler.core.components.database.db.knowledge_db import ResourceType from tribler.core.components.libtorrent.torrentdef import TorrentDef from tribler.core.components.metadata_store.category_filter.family_filter import default_xxx_filter from tribler.core.components.metadata_store.db.orm_bindings.channel_node import NEW diff --git a/src/tribler/core/components/metadata_store/restapi/tests/test_search_endpoint.py b/src/tribler/core/components/metadata_store/restapi/tests/test_search_endpoint.py index 3c6a91a1fc9..6c44b482354 100644 --- a/src/tribler/core/components/metadata_store/restapi/tests/test_search_endpoint.py +++ b/src/tribler/core/components/metadata_store/restapi/tests/test_search_endpoint.py @@ -6,7 +6,7 @@ import pytest from pony.orm import db_session -from tribler.core.components.knowledge.db.knowledge_db import KnowledgeDatabase +from tribler.core.components.database.db.knowledge_db import KnowledgeDatabase from tribler.core.components.metadata_store.db.serialization import REGULAR_TORRENT, SNIPPET from tribler.core.components.metadata_store.restapi.search_endpoint import SearchEndpoint from tribler.core.components.restapi.rest.base_api_test import do_request diff --git a/src/tribler/core/components/metadata_store/tests/test_metadata_store_component.py b/src/tribler/core/components/metadata_store/tests/test_metadata_store_component.py index fdde51ffe50..3aaae2bc544 100644 --- a/src/tribler/core/components/metadata_store/tests/test_metadata_store_component.py +++ b/src/tribler/core/components/metadata_store/tests/test_metadata_store_component.py @@ -1,3 +1,4 @@ +from tribler.core.components.database.database_component import DatabaseComponent from tribler.core.components.ipv8.ipv8_component import Ipv8Component from tribler.core.components.key.key_component import KeyComponent from tribler.core.components.knowledge.knowledge_component import KnowledgeComponent @@ -9,7 +10,7 @@ async def test_metadata_store_component(tribler_config): - components = [KnowledgeComponent(), Ipv8Component(), KeyComponent(), MetadataStoreComponent()] + components = [DatabaseComponent(), KnowledgeComponent(), Ipv8Component(), KeyComponent(), MetadataStoreComponent()] async with Session(tribler_config, components) as session: comp = session.get_instance(MetadataStoreComponent) assert comp.started_event.is_set() and not comp.failed diff --git a/src/tribler/core/components/metadata_store/utils.py b/src/tribler/core/components/metadata_store/utils.py index 53636ae45eb..fe09d62d4d5 100644 --- a/src/tribler/core/components/metadata_store/utils.py +++ b/src/tribler/core/components/metadata_store/utils.py @@ -6,7 +6,7 @@ from pony.orm import db_session from tribler.core.components.knowledge.community.knowledge_payload import StatementOperation -from tribler.core.components.knowledge.db.knowledge_db import KnowledgeDatabase, Operation, ResourceType +from tribler.core.components.database.db.knowledge_db import KnowledgeDatabase, Operation, ResourceType from tribler.core.components.knowledge.knowledge_constants import MIN_RESOURCE_LENGTH from tribler.core.components.metadata_store.db.store import MetadataStore from tribler.core.tests.tools.common import PNG_FILE diff --git a/src/tribler/core/components/popularity/tests/test_popularity_component.py b/src/tribler/core/components/popularity/tests/test_popularity_component.py index b267d3f4eb2..64f7309699d 100644 --- a/src/tribler/core/components/popularity/tests/test_popularity_component.py +++ b/src/tribler/core/components/popularity/tests/test_popularity_component.py @@ -1,3 +1,4 @@ +from tribler.core.components.database.database_component import DatabaseComponent from tribler.core.components.ipv8.ipv8_component import Ipv8Component from tribler.core.components.key.key_component import KeyComponent from tribler.core.components.knowledge.knowledge_component import KnowledgeComponent @@ -13,8 +14,9 @@ async def test_popularity_component(tribler_config): - components = [SocksServersComponent(), LibtorrentComponent(), TorrentCheckerComponent(), KnowledgeComponent(), - MetadataStoreComponent(), KeyComponent(), Ipv8Component(), PopularityComponent()] + components = [DatabaseComponent(), SocksServersComponent(), LibtorrentComponent(), TorrentCheckerComponent(), + KnowledgeComponent(), MetadataStoreComponent(), KeyComponent(), Ipv8Component(), + PopularityComponent()] async with Session(tribler_config, components) as session: comp = session.get_instance(PopularityComponent) assert comp.community diff --git a/src/tribler/core/components/restapi/restapi_component.py b/src/tribler/core/components/restapi/restapi_component.py index e1e6073a0a0..6a28d151871 100644 --- a/src/tribler/core/components/restapi/restapi_component.py +++ b/src/tribler/core/components/restapi/restapi_component.py @@ -6,6 +6,7 @@ from tribler.core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent from tribler.core.components.bandwidth_accounting.restapi.bandwidth_endpoint import BandwidthEndpoint from tribler.core.components.component import Component +from tribler.core.components.database.database_component import DatabaseComponent from tribler.core.components.exceptions import NoneComponent from tribler.core.components.gigachannel.gigachannel_component import GigaChannelComponent from tribler.core.components.gigachannel_manager.gigachannel_manager_component import GigachannelManagerComponent @@ -84,6 +85,7 @@ async def run(self): tunnel_component = await self.maybe_component(TunnelsComponent) torrent_checker_component = await self.maybe_component(TorrentCheckerComponent) gigachannel_manager_component = await self.maybe_component(GigachannelManagerComponent) + db_component = await self.maybe_component(DatabaseComponent) public_key = key_component.primary_key.key.pk if not isinstance(key_component, NoneComponent) else b'' self._events_endpoint = EventsEndpoint(notifier, public_key=hexlify(public_key)) @@ -109,15 +111,15 @@ async def run(self): self.maybe_add(LibTorrentEndpoint, libtorrent_component.download_manager) self.maybe_add(TorrentInfoEndpoint, libtorrent_component.download_manager) self.maybe_add(MetadataEndpoint, torrent_checker, metadata_store_component.mds, - knowledge_db=knowledge_component.knowledge_db, + knowledge_db=db_component.db, tag_rules_processor=knowledge_component.rules_processor) self.maybe_add(ChannelsEndpoint, libtorrent_component.download_manager, gigachannel_manager, gigachannel_component.community, metadata_store_component.mds, - knowledge_db=knowledge_component.knowledge_db, + knowledge_db=db_component.db, tag_rules_processor=knowledge_component.rules_processor) - self.maybe_add(SearchEndpoint, metadata_store_component.mds, knowledge_db=knowledge_component.knowledge_db) + self.maybe_add(SearchEndpoint, metadata_store_component.mds, knowledge_db=db_component.db) self.maybe_add(RemoteQueryEndpoint, gigachannel_component.community, metadata_store_component.mds) - self.maybe_add(KnowledgeEndpoint, db=knowledge_component.knowledge_db, community=knowledge_component.community) + self.maybe_add(KnowledgeEndpoint, db=db_component.db, community=knowledge_component.community) if not isinstance(ipv8_component, NoneComponent): ipv8_root_endpoint = IPV8RootEndpoint() diff --git a/src/tribler/core/components/restapi/tests/test_restapi_component.py b/src/tribler/core/components/restapi/tests/test_restapi_component.py index d9da02ce6c8..fe9f8fc8f8a 100644 --- a/src/tribler/core/components/restapi/tests/test_restapi_component.py +++ b/src/tribler/core/components/restapi/tests/test_restapi_component.py @@ -3,6 +3,7 @@ import pytest from tribler.core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent +from tribler.core.components.database.database_component import DatabaseComponent from tribler.core.components.exceptions import NoneComponent from tribler.core.components.gigachannel.gigachannel_component import GigaChannelComponent from tribler.core.components.ipv8.ipv8_component import Ipv8Component @@ -22,7 +23,7 @@ async def test_rest_component(tribler_config): components = [KeyComponent(), RESTComponent(), Ipv8Component(), LibtorrentComponent(), ResourceMonitorComponent(), BandwidthAccountingComponent(), GigaChannelComponent(), KnowledgeComponent(), SocksServersComponent(), - MetadataStoreComponent()] + MetadataStoreComponent(), DatabaseComponent()] async with Session(tribler_config, components) as session: # Test REST component starts normally comp = session.get_instance(RESTComponent) diff --git a/src/tribler/core/components/torrent_checker/tests/test_torrent_checker_component.py b/src/tribler/core/components/torrent_checker/tests/test_torrent_checker_component.py index 28ef90bb1de..b66880a811a 100644 --- a/src/tribler/core/components/torrent_checker/tests/test_torrent_checker_component.py +++ b/src/tribler/core/components/torrent_checker/tests/test_torrent_checker_component.py @@ -1,3 +1,4 @@ +from tribler.core.components.database.database_component import DatabaseComponent from tribler.core.components.ipv8.ipv8_component import Ipv8Component from tribler.core.components.key.key_component import KeyComponent from tribler.core.components.knowledge.knowledge_component import KnowledgeComponent @@ -10,7 +11,7 @@ # pylint: disable=protected-access async def test_torrent_checker_component(tribler_config): - components = [SocksServersComponent(), LibtorrentComponent(), KeyComponent(), + components = [DatabaseComponent(), SocksServersComponent(), LibtorrentComponent(), KeyComponent(), Ipv8Component(), KnowledgeComponent(), MetadataStoreComponent(), TorrentCheckerComponent()] async with Session(tribler_config, components) as session: comp = session.get_instance(TorrentCheckerComponent) diff --git a/src/tribler/core/start_core.py b/src/tribler/core/start_core.py index 746a1cc577e..ee488684366 100644 --- a/src/tribler/core/start_core.py +++ b/src/tribler/core/start_core.py @@ -14,6 +14,7 @@ ) from tribler.core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent from tribler.core.components.component import Component +from tribler.core.components.database.database_component import DatabaseComponent from tribler.core.components.gigachannel.gigachannel_component import GigaChannelComponent from tribler.core.components.gigachannel_manager.gigachannel_manager_component import GigachannelManagerComponent from tribler.core.components.gui_process_watcher.gui_process_watcher import GuiProcessWatcher @@ -55,6 +56,7 @@ def components_gen(config: TriblerConfig): """ yield ReporterComponent() yield GuiProcessWatcherComponent() + yield DatabaseComponent() yield RESTComponent() if config.chant.enabled or config.torrent_checking.enabled: yield MetadataStoreComponent() diff --git a/src/tribler/core/upgrade/tags_to_knowledge/migration.py b/src/tribler/core/upgrade/tags_to_knowledge/migration.py index 6712a5efbf1..16339e71438 100644 --- a/src/tribler/core/upgrade/tags_to_knowledge/migration.py +++ b/src/tribler/core/upgrade/tags_to_knowledge/migration.py @@ -7,7 +7,7 @@ from pony.orm import db_session, select from tribler.core.components.knowledge.community.knowledge_payload import StatementOperation -from tribler.core.components.knowledge.db.knowledge_db import KnowledgeDatabase, ResourceType +from tribler.core.components.database.db.knowledge_db import KnowledgeDatabase, ResourceType from tribler.core.upgrade.tags_to_knowledge.tags_db import TagDatabase from tribler.core.utilities.path_util import Path from tribler.core.utilities.simpledefs import STATEDIR_DB_DIR diff --git a/src/tribler/core/upgrade/tags_to_knowledge/tests/test_migration.py b/src/tribler/core/upgrade/tags_to_knowledge/tests/test_migration.py index 47b79f00fe8..e4973797aad 100644 --- a/src/tribler/core/upgrade/tags_to_knowledge/tests/test_migration.py +++ b/src/tribler/core/upgrade/tags_to_knowledge/tests/test_migration.py @@ -7,7 +7,7 @@ from pony.orm import db_session from tribler.core.components.knowledge.community.knowledge_payload import StatementOperation -from tribler.core.components.knowledge.db.knowledge_db import KnowledgeDatabase +from tribler.core.components.database.db.knowledge_db import KnowledgeDatabase from tribler.core.upgrade.tags_to_knowledge.migration import MigrationTagsToKnowledge from tribler.core.upgrade.tags_to_knowledge.tags_db import TagDatabase from tribler.core.utilities.simpledefs import STATEDIR_DB_DIR diff --git a/src/tribler/gui/dialogs/editmetadatadialog.py b/src/tribler/gui/dialogs/editmetadatadialog.py index 5eae9cf6837..6e296f92ddb 100644 --- a/src/tribler/gui/dialogs/editmetadatadialog.py +++ b/src/tribler/gui/dialogs/editmetadatadialog.py @@ -4,7 +4,7 @@ from PyQt5.QtCore import QModelIndex, QPoint, Qt, pyqtSignal from PyQt5.QtWidgets import QComboBox, QSizePolicy, QWidget -from tribler.core.components.knowledge.db.knowledge_db import ResourceType +from tribler.core.components.database.db.knowledge_db import ResourceType from tribler.core.components.knowledge.knowledge_constants import MAX_RESOURCE_LENGTH, MIN_RESOURCE_LENGTH from tribler.gui.defs import TAG_HORIZONTAL_MARGIN from tribler.gui.dialogs.dialogcontainer import DialogContainer diff --git a/src/tribler/gui/tests/test_gui.py b/src/tribler/gui/tests/test_gui.py index 5fcf30050b8..28b870fa361 100644 --- a/src/tribler/gui/tests/test_gui.py +++ b/src/tribler/gui/tests/test_gui.py @@ -10,7 +10,7 @@ from PyQt5.QtWidgets import QListWidget, QTableView, QTextEdit, QTreeWidget, QTreeWidgetItem import tribler.gui -from tribler.core.components.knowledge.db.knowledge_db import ResourceType +from tribler.core.components.database.db.knowledge_db import ResourceType from tribler.core.components.knowledge.knowledge_constants import MIN_RESOURCE_LENGTH from tribler.core.components.reporter.reported_error import ReportedError from tribler.core.sentry_reporter.sentry_reporter import SentryReporter diff --git a/src/tribler/gui/utilities.py b/src/tribler/gui/utilities.py index bbaeff9da55..71165adb260 100644 --- a/src/tribler/gui/utilities.py +++ b/src/tribler/gui/utilities.py @@ -27,7 +27,7 @@ from PyQt5.QtWidgets import QApplication, QMessageBox import tribler.gui -from tribler.core.components.knowledge.db.knowledge_db import ResourceType +from tribler.core.components.database.db.knowledge_db import ResourceType from tribler.gui.defs import HEALTH_DEAD, HEALTH_GOOD, HEALTH_MOOT, HEALTH_UNCHECKED # fmt: off diff --git a/src/tribler/gui/widgets/tablecontentdelegate.py b/src/tribler/gui/widgets/tablecontentdelegate.py index 90ea1fab6f1..15bbaf98a84 100644 --- a/src/tribler/gui/widgets/tablecontentdelegate.py +++ b/src/tribler/gui/widgets/tablecontentdelegate.py @@ -6,7 +6,7 @@ from PyQt5.QtWidgets import QApplication, QComboBox, QStyle, QStyleOptionViewItem, QStyledItemDelegate, QToolTip from psutil import LINUX -from tribler.core.components.knowledge.db.knowledge_db import ResourceType +from tribler.core.components.database.db.knowledge_db import ResourceType from tribler.core.components.metadata_store.db.orm_bindings.channel_node import LEGACY_ENTRY from tribler.core.components.metadata_store.db.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT, \ SNIPPET