-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
chore: throttle exceptions counter increment #29719
Conversation
|
packages/tools/src/counter.ts
Outdated
import throttle from 'lodash.throttle'; | ||
|
||
export function throttledCounter(fn: (counter: number) => unknown, wait: number) { | ||
let counter = 0; | ||
|
||
const throttledFn = throttle( | ||
() => { | ||
fn(counter); | ||
|
||
counter = 0; | ||
}, | ||
wait, | ||
{ leading: false }, | ||
); | ||
|
||
return () => { | ||
counter++; | ||
throttledFn(); | ||
}; | ||
} |
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 dont think this should be placed here, its not quite useful outside that scope
not sure about the lodash
necessity as well
Codecov Report
@@ Coverage Diff @@
## develop #29719 +/- ##
============================================
+ Coverage 31.33% 46.58% +15.25%
============================================
Files 570 693 +123
Lines 10839 12946 +2107
Branches 1993 2242 +249
============================================
+ Hits 3396 6031 +2635
+ Misses 7229 6589 -640
- Partials 214 326 +112
Flags with carried forward coverage won't be shown. Click here to find out more. |
|
||
import { settings } from '../../../settings/server'; | ||
import { sendMessage } from '../../../lib/server'; | ||
|
||
const incException = throttledCounter((counter) => { |
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.
wdyt of ignoring this setting on the watch.settings
watcher?
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.
the main issue is that we'd still receive it from mongo.. so we'd need to remove it on oplog/change stream query, which is not good 😬
packages/tools/src/counter.ts
Outdated
import throttle from 'lodash.throttle'; | ||
|
||
export function throttledCounter(fn: (counter: number) => unknown, wait: number) { | ||
let counter = 0; | ||
|
||
const throttledFn = throttle( | ||
() => { | ||
fn(counter); | ||
|
||
counter = 0; | ||
}, | ||
wait, | ||
{ leading: false }, | ||
); | ||
|
||
return () => { | ||
counter++; | ||
throttledFn(); | ||
}; | ||
} |
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.
import throttle from 'lodash.throttle'; | |
export function throttledCounter(fn: (counter: number) => unknown, wait: number) { | |
let counter = 0; | |
const throttledFn = throttle( | |
() => { | |
fn(counter); | |
counter = 0; | |
}, | |
wait, | |
{ leading: false }, | |
); | |
return () => { | |
counter++; | |
throttledFn(); | |
}; | |
} | |
export const throttle = <R, A extends any[]>( | |
fn: (...args: A) => R, | |
delay: number | |
) => { | |
let wait = false; | |
let timeout: undefined | number; | |
return Object.assign( | |
(...args: A) => { | |
if (wait) return undefined; | |
const val = fn(...args); | |
wait = true; | |
timeout = window.setTimeout(() => { | |
wait = false; | |
}, delay); | |
return val; | |
}, { | |
stop: () => { | |
clearTimeout(timeout); | |
}, | |
}); | |
}; |
@@ -1,9 +1,14 @@ | |||
import { Meteor } from 'meteor/meteor'; | |||
import { Settings, Users, Rooms } from '@rocket.chat/models'; | |||
import { throttledCounter } from '@rocket.chat/tools'; |
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.
import { throttledCounter } from '@rocket.chat/tools'; | |
import { throttle } from '@rocket.chat/tools'; |
const incException = throttledCounter((counter) => { | ||
Settings.incrementValueById('Uncaught_Exceptions_Count', counter).catch(console.error); | ||
}, 10000); | ||
|
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.
const incException = throttledCounter((counter) => { | |
Settings.incrementValueById('Uncaught_Exceptions_Count', counter).catch(console.error); | |
}, 10000); | |
const incException = (() => { | |
let counter = 0; | |
const commit = throttle((increment: number) => { | |
console.log(counter); | |
counter = 0; | |
}, 10000); | |
return () => { | |
counter++; | |
commit(counter); | |
}; | |
})() |
03be8c3
to
5661935
Compare
…/reportUser * 'develop' of github.com:RocketChat/Rocket.Chat: (28 commits) feat: Add missing variants to UIKit button (#29654) refactor: Remove Accountbox usage (#29786) chore: stop importing action manager as global (#29766) chore: create FeaturePreview Component (#29759) regression: add missing translations on MenuV2 replace (#29777) test: create mock package (#29765) fix: Prevent app's bridges from overriding lastMsg prop on rooms col (#29756) regression: option to start video conferences disappearing for regular users (#29763) Release 6.2.9 Revert "Release 6.2.9" fix(meteor): `room-opened` event not dispatching when navigating cached rooms (#29718) chore: device management improve readability and performance (#29712) chore: throttle exceptions counter increment (#29719) chore: Improve performance of getActiveLocalUserCount (#29681) Release 6.2.9 ci: update EE license (#29684) ci: Add missing `context` property on compose file (#29676) chore: add change stream option to get full doc (#29627) fix(meteor): Message composer keeps recording even though permission was denied (#29526) fix(meteor): Video Record button disabled on iOS browsers (#29649) ...
Proposed changes (including videos or screenshots)
Throttle down uncaught exceptions counter to every 10 seconds. This is to avoid too many operations into the settings collection.
Issue(s)
Steps to test or reproduce
Further comments