generated from 8iq/nodejs-hackathon-boilerplate-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 27
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
fix(condo): DOMA-10006 add throttling #5126
Merged
Merged
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -9,8 +9,9 @@ import intersectionWith from 'lodash/intersectionWith' | |
import isEqual from 'lodash/isEqual' | ||
import map from 'lodash/map' | ||
import slice from 'lodash/slice' | ||
import throttle from 'lodash/throttle' | ||
import uniq from 'lodash/uniq' | ||
import React, { CSSProperties, useEffect, useMemo, useState } from 'react' | ||
import React, { CSSProperties, useCallback, useEffect, useMemo, useState } from 'react' | ||
|
||
import { useAuth } from '@open-condo/next/auth' | ||
import { useIntl } from '@open-condo/next/intl' | ||
|
@@ -237,11 +238,13 @@ export const RecipientCounter: React.FC<RecipientCounterProps> = ({ newsItemScop | |
}, | ||
) | ||
|
||
const throttledGetCounters = useCallback(throttle(getCounters, 1500), [throttle]) | ||
|
||
useEffect(() => { | ||
const sender = getClientSideSenderInfo() | ||
const meta = { dv: 1, sender } | ||
|
||
getCounters({ | ||
throttledGetCounters({ | ||
variables: { | ||
data: { | ||
newsItemScopes: processedNewsItemScope, | ||
|
@@ -266,6 +269,9 @@ export const RecipientCounter: React.FC<RecipientCounterProps> = ({ newsItemScop | |
|
||
const isLoadingCounters = isCountersLoading || !counters | ||
|
||
console.log('Recipient counter', { isLoadingCounters, isCountersLoading, counters }) | ||
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. ? |
||
|
||
|
||
return ( | ||
<RecipientCounterContainer | ||
title={<>{MailingMessage}<Typography.Text strong>{message}</Typography.Text></>} | ||
|
@@ -341,7 +347,7 @@ const NewsSharingRecipientCounter: React.FC<{ contextId: string, newsItemScopes: | |
}, | ||
}, | ||
}) | ||
}, [getCounter, contextId, newsItemScopes]) | ||
}, [ getCounter, contextId, newsItemScopes ]) | ||
|
||
// if typeof counter !== number is used here instead of just if !counter because bool(0) => false | ||
const isLoadingCounter = isCounterLoading || typeof counter !== 'number' | ||
|
@@ -357,4 +363,6 @@ const NewsSharingRecipientCounter: React.FC<{ contextId: string, newsItemScopes: | |
) | ||
} | ||
|
||
export const MemoizedRecipientCounter = React.memo(RecipientCounter) | ||
|
||
export const MemoizedNewsSharingRecipientCounter = React.memo(NewsSharingRecipientCounter) |
Oops, something went wrong.
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.
Why
getCounters
not in deps array? To avoid callback rerender?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.
btw, throttle is imported function, its not necessary to put it in deps
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.
And why 1500? I'm almost sure we can reproduce error consistently with this value