-
Notifications
You must be signed in to change notification settings - Fork 0
ERA-10594: Leverage read
filter param in messages API calls from das-web-react
#1270
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 all commits
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 |
---|---|---|
|
@@ -10,7 +10,8 @@ import { | |
fetchAllMessages, | ||
fetchMessagesSuccess, | ||
fetchUnreadMessagesCount, | ||
updateMessageFromRealtime, updateUnreadMessagesCount | ||
updateMessageFromRealtime, | ||
updateUnreadMessagesCount | ||
} from '../ducks/messaging'; | ||
import MessageContext from '../InReach/context'; | ||
|
||
|
@@ -45,7 +46,7 @@ const MessageMenu = () => { | |
|
||
const checkForUnreadMessages = useCallback(() => { | ||
fetchUnreadMessagesCount() | ||
.then(({ data: { data: { count } } }) => dispatch(updateUnreadMessagesCount(count))) | ||
.then(({ data: { data: { results } } }) => dispatch(updateUnreadMessagesCount({ results }) )) | ||
.catch((error) => console.warn('error checking for unread messages', { error })); | ||
}, [dispatch]); | ||
|
||
|
@@ -58,8 +59,10 @@ const MessageMenu = () => { | |
}, [dispatch]); | ||
|
||
useEffect(() => { | ||
checkForUnreadMessages(); | ||
}, [checkForUnreadMessages, state.results]); | ||
if (subjects.length > 0){ | ||
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. Also, the |
||
checkForUnreadMessages(); | ||
} | ||
}, [checkForUnreadMessages, state.results, subjects]); | ||
|
||
return canShowMessageMenu ? <Dropdown | ||
align="end" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ export const updateUnreadMessagesCount = (payload) => ({ | |
|
||
const { get, post } = axios; | ||
|
||
export const fetchUnreadMessagesCount = () => axios.get(`${MESSAGING_API_URL}?include_additional_data=false&page_size=0&read=false`); | ||
export const fetchUnreadMessagesCount = () => axios.get(`${MESSAGING_API_URL}?include_additional_data=false&page_size=10&read=false`); | ||
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 added the 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 is it better to have a page size of 10 instead of 0? Having a page size of 0 made the response extremely small of size 🤔 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. Because the messages are needed, they need to be filtered out, if there is an unread message it does not mean that is valid for user to be seen, it needs to be compared against the subject store to check for the Honestly I think this responsibility should be part of the backend calculations, the API should be able to say 'Here are the unread message that concerns only you' but it doesn't, not sure why 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. Ok this bit is clear. But then, again, only fetching 10 has a clear bug. I think we need to fetch them all because we don't know if we have 100 messages and just the last 10 are valid for display. If we only fetch the first 10, they will be filtered and show no notification badge. @JoshuaVulcan The fact that we need to filter them in the client doesn't really let us optimize this IMO. |
||
|
||
export const fetchMessages = (params = {}) => { | ||
const paramString = objectToParamString( | ||
|
@@ -106,7 +106,7 @@ export const messageListReducer = (state = INITIAL_MESSAGE_LIST_STATE, action) = | |
if (type === UPDATE_UNREAD_MESSAGES_COUNT) { | ||
return { | ||
...state, | ||
unreadMessagesCount: payload, | ||
unreadMessagesCount: payload.results.filter(msg => messageIsValidForDisplay(msg, store.getState().data.subjectStore)).length, | ||
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 filter might be controversial, but due the 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 think there's a logical error here. We are just asking for 10 results and then doing this filter, which may filter out only 5 messages, so we would assume there are 5 unread messages. But isn't it possible that in the next page (the next 10 results) we have more unread messages that would pass the filter? That sounds possible. We may filter out some results from the first page but maybe there are more valid unread messages in the next pages. 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. For me it kind of sounds like a design problem, because currently We are being hacky with the GET API of messaging, in that case We should have an endpoint for checking specifically the unread messages count, right? 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. Hmm I don't get why a design problem 🤔 I mean, I think this logic of fetching 10 and filtering (that is added in this PR) sounds like has a logical issue: If you have 20 messages in DB and first 10 won't pass this 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. That is correcto, but the whole point of this ticket was to optimize the calculation of unread messages, so now We have to add pagination to it? For me it kind of impact the optimization goal 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. Yeah but the idea is to optimize it without injecting a bug 😓 What's the benefit for our users if we make it faster but broken? If that is not possible, then I agree with Joshua: let's close this ticket and ask the backend guys for an endpoint update to return only the valid messages. |
||
}; | ||
} | ||
|
||
|
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.
Hmm I don't understand why now we are caring about the results instead of just the count (a number) of unread messages.
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.
Check the need of filtering valid messages for the user, having just a count is not enough