-
Notifications
You must be signed in to change notification settings - Fork 333
Add new API to list paginated qualified conv ids #1686
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
Changes from 11 commits
b96e168
b059cfa
157045e
4b096a1
febb54b
076cacd
6cda742
082f2e8
5888386
93d84fb
02a8ca3
1967334
3d91255
db741e7
064a3fc
351919f
18ff99c
5b769e0
a0dd768
1285218
3a70ff2
b5495a5
da349b6
aef1401
c138c4a
4cb8cca
007baff
c003902
0810f89
8ca1d9b
b66a276
a5f79bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,7 @@ module Galley.Data | |
| updateConversationMessageTimer, | ||
| deleteConversation, | ||
| lookupReceiptMode, | ||
| remoteConversationIdsFrom, | ||
|
|
||
| -- * Conversation Members | ||
| addMember, | ||
|
|
@@ -551,6 +552,30 @@ conversationIdsFrom usr start (fromRange -> max) = | |
| where | ||
| strip p = p {result = take (fromIntegral max) (result p)} | ||
|
|
||
| -- | When the 'start' parameter is set to 'Nothing', reads first 'max' records | ||
| -- from 'user_remote_converstaions' table. | ||
| -- | ||
| -- Otherwise, reads 'max' records starting from the 'start' parameter. Doing | ||
| -- this is unfortunately not trivial, so this function first gets all the | ||
| -- conversations which match the domain and then if there is still space, gets | ||
| -- the conversations which have domain > domain of start. | ||
|
Contributor
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. I imagine this is necessary because there is no way in cassandra to say
Member
Author
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. Not exactly this, but there is a
Member
Author
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. From my reading so far
Member
Author
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. Actually, the partition key doesn't need to be unique, so we can even get rid of
Contributor
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. But why not use
Member
Author
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.
I will try this next and see if it works.
Member
Author
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 actually works 🎉 |
||
| remoteConversationIdsFrom :: (MonadClient m, MonadLogger m) => UserId -> Maybe (Qualified ConvId) -> Int32 -> m (ResultSet (Qualified ConvId)) | ||
| remoteConversationIdsFrom usr start max = | ||
| case start of | ||
| Just (Qualified c d) -> do | ||
| domainPage <- toResultSet max <$> paginate Cql.selectUserRemoteConvsForDomainFrom (paramsP Quorum (usr, d, c) (max + 1)) | ||
| let remainingMax = max - fromIntegral (length (resultSetResult domainPage)) | ||
| if resultSetType domainPage == ResultSetTruncated | ||
| then pure domainPage | ||
| else do | ||
| nextPage <- toResultSet remainingMax <$> paginate Cql.selectUserRemoteConvsFromDomain (paramsP Quorum (usr, d) (remainingMax + 1)) | ||
| pure $ nextPage {resultSetResult = resultSetResult domainPage <> resultSetResult nextPage} | ||
|
Contributor
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 idiom of using
Member
Author
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 is no longer required, so maybe we can just retire this thing soon. |
||
| Nothing -> | ||
| toResultSet max <$> paginate Cql.selectUserRemoteConvs (paramsP Quorum (Identity usr) (max + 1)) | ||
| where | ||
| toResultSet max' = mkResultSet . strip max' . fmap (uncurry (flip Qualified)) | ||
| strip max' p = p {result = take (fromIntegral max') (result p)} | ||
|
|
||
| conversationIdRowsForPagination :: MonadClient m => UserId -> Maybe ConvId -> Range 1 1000 Int32 -> m (Page ConvId) | ||
| conversationIdRowsForPagination usr start (fromRange -> max) = | ||
| runIdentity | ||
|
|
||
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.
How about converting this to use
conversationIdsPageFrom, so we can remove the legacy functions and even theResultSettype?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 like the new name, I don't know if we can easily remove the
ResultSettype. I will look into it, but let's do it in the next PR?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.
👍