-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: add and remove conversation favorite [WPB-11639] #3119
Conversation
Bencher Report
Click to view all benchmark results
|
Datadog ReportBranch report: ✅ 0 Failed, 3220 Passed, 107 Skipped, 36.5s Total Time |
END AS interactionEnabled, | ||
CASE WHEN EXISTS ( | ||
SELECT 1 | ||
FROM LabeledConversation lc | ||
JOIN ConversationFolder cf ON lc.folder_id = cf.id | ||
WHERE lc.conversation_id = Conversation.qualified_id | ||
AND cf.folder_type = 'FAVORITE' | ||
) | ||
THEN 1 ELSE 0 END AS isFavorite |
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.
suggestion: making multiple nested queries can be expensive.
I would suggest to change it to use joins, like:
LabeledConversation.folder_id IS NOT NULL AS isFavorite
FROM Conversation
LEFT JOIN ConversationFolder AS FavoriteFolder ON FavoriteFolder.folder_type = 'FAVORITE'
LEFT JOIN LabeledConversation ON LabeledConversation.conversation_id = Conversation.id AND LabeledConversation.folder_id = FavoriteFolder.id
First left join filters out and joins only favorite folder, second left join adds given conversation's folders but filters them so that it only adds the one which matches with favorite folder id, so in the end LabeledConversation.folder_id
is equal to favorite folder id or NULL if this conversation is not in favorite folder 😄
@@ -17,6 +17,19 @@ CREATE TABLE LabeledConversation ( | |||
PRIMARY KEY (folder_id, conversation_id) | |||
); | |||
|
|||
getFolderWithConversations: |
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.
question: is it supposed to return all folders? Then maybe name it getAllFoldersWithConversations
? 🤔
@@ -0,0 +1,125 @@ | |||
/* |
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.
change: name of the file is RemoveConversationFromFaroritesUseCase
without Test
at the end 😄
return wrapStorageRequest { | ||
conversationFolderDAO.addConversationToFolder(conversationId.toDao(), folderId) | ||
} | ||
.flatMap { | ||
syncConversationFoldersFromLocal() | ||
} | ||
} |
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.
I'd suggest to move syncConversationFoldersFromLocal()
to the usecase.
Repository should stay as dummy class, it just interacts with data sources by providing CRUD operations and do data transformation.
}.flatMap { | ||
syncConversationFoldersFromLocal() | ||
} |
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.
same here
override suspend fun syncConversationFoldersFromLocal(): Either<CoreFailure, Unit> { | ||
kaliumLogger.withFeatureId(CONVERSATIONS_FOLDERS).v("Syncing conversation folders from local") | ||
return wrapStorageRequest { conversationFolderDAO.getFoldersWithConversations().map { it.toModel() } } | ||
.flatMap { | ||
wrapApiRequest { | ||
userPropertiesApi.updateLabels( | ||
LabelListResponseDTO(it.map { it.toLabel() }) | ||
) | ||
} | ||
} | ||
} |
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 is also breaking the separation of concerns.
We can have this logic in a use case, as it's responsible for orchestrating business logic.
Quality Gate passedIssues Measures |
PR Submission Checklist for internal contributors
The PR Title
SQPIT-764
The PR Description
What's new in this PR?
syncConversationFoldersFromLocal
for updating all folders from local to APIisFavorite
to conversation details view