-
Notifications
You must be signed in to change notification settings - Fork 451
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
Add CONTENT_ITEM
relation
#7445
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
MIN_RESOURCE_LENGTH = 3 | ||
MIN_RESOURCE_LENGTH = 2 | ||
MAX_RESOURCE_LENGTH = 50 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ | |
|
||
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.knowledge.knowledge_constants import MAX_RESOURCE_LENGTH, MIN_RESOURCE_LENGTH | ||
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 | ||
|
@@ -65,24 +65,21 @@ async def update_knowledge_entries(self, request): | |
return error_response | ||
|
||
# Validate whether the size of the tag is within the allowed range and filter out duplicate tags. | ||
tags = set() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
statements = [] | ||
self._logger.info(f'Statements about {infohash}: {params["statements"]}') | ||
for statement in params["statements"]: | ||
obj = statement["object"] | ||
if statement["predicate"] == ResourceType.TAG and \ | ||
(len(obj) < MIN_RESOURCE_LENGTH or len(obj) > MAX_RESOURCE_LENGTH): | ||
if not is_valid_resource(obj): | ||
return RESTResponse({"error": "Invalid tag length"}, status=HTTP_BAD_REQUEST) | ||
|
||
if obj not in tags: | ||
tags.add(obj) | ||
statements.append(statement) | ||
statements.append(statement) | ||
|
||
self.modify_statements(infohash, statements) | ||
|
||
return RESTResponse({"success": True}) | ||
|
||
@db_session | ||
def modify_statements(self, infohash: str, statements): | ||
def modify_statements(self, infohash: str, statements: list): | ||
""" | ||
Modify the statements of a particular content item. | ||
""" | ||
|
@@ -92,7 +89,9 @@ def modify_statements(self, infohash: str, statements): | |
# First, get the current statements and compute the diff between the old and new statements | ||
old_statements = self.db.get_statements(subject_type=ResourceType.TORRENT, subject=infohash) | ||
old_statements = {(stmt.predicate, stmt.object) for stmt in old_statements} | ||
self._logger.info(f'Old statements: {old_statements}') | ||
new_statements = {(stmt["predicate"], stmt["object"]) for stmt in statements} | ||
self._logger.info(f'New statements: {new_statements}') | ||
added_statements = new_statements - old_statements | ||
removed_statements = old_statements - new_statements | ||
|
||
|
@@ -109,6 +108,9 @@ def modify_statements(self, infohash: str, statements): | |
signature = self.community.sign(operation) | ||
self.db.add_operation(operation, signature, is_local_peer=True) | ||
|
||
self._logger.info(f'Added statements: {added_statements}') | ||
self._logger.info(f'Removed statements: {removed_statements}') | ||
|
||
@docs( | ||
tags=["General"], | ||
summary="Get tag suggestions for a torrent with a particular infohash.", | ||
|
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
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
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
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
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
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
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.
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.
This change is necessary for the language statements transfer (nl, ru, en)