refactor(pads): improve session creation
Add a throttle control to avoid multiple create session calls in a short period of time.
This commit is contained in:
parent
3853d9f799
commit
307a6cb83c
@ -1,9 +1,11 @@
|
||||
import _ from 'lodash';
|
||||
import Pads, { PadsUpdates } from '/imports/api/pads';
|
||||
import { makeCall } from '/imports/ui/services/api';
|
||||
import Auth from '/imports/ui/services/auth';
|
||||
import Settings from '/imports/ui/services/settings';
|
||||
|
||||
const PADS_CONFIG = Meteor.settings.public.pads;
|
||||
const THROTTLE_TIMEOUT = 2000;
|
||||
|
||||
const getLang = () => {
|
||||
const { locale } = Settings.application;
|
||||
@ -38,6 +40,11 @@ const hasPad = (externalId) => {
|
||||
|
||||
const createSession = (externalId) => makeCall('createSession', externalId);
|
||||
|
||||
const throttledCreateSession = _.throttle(createSession, THROTTLE_TIMEOUT, {
|
||||
leading: true,
|
||||
trailing: false,
|
||||
});
|
||||
|
||||
const buildPadURL = (padId) => {
|
||||
if (padId) {
|
||||
const params = getParams();
|
||||
@ -89,7 +96,7 @@ export default {
|
||||
getPadId,
|
||||
createGroup,
|
||||
hasPad,
|
||||
createSession,
|
||||
createSession: (externalId) => throttledCreateSession(externalId),
|
||||
buildPadURL,
|
||||
getRev,
|
||||
getPadTail,
|
||||
|
Loading…
Reference in New Issue
Block a user