Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d11a436

Browse files
authoredJan 27, 2024
Merge pull request #11452 from nextcloud/feat/noid/fix-debounce-functions
chore(deps): update all debounce methods
2 parents 6fa0467 + 4a9952f commit d11a436

16 files changed

+123
-84
lines changed
 

‎src/App.vue

+7-6
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export default {
9696
loading: false,
9797
isRefreshingCurrentConversation: false,
9898
recordingConsentGiven: false,
99+
debounceRefreshCurrentConversation: () => {},
99100
}
100101
},
101102

@@ -256,6 +257,7 @@ export default {
256257
},
257258

258259
beforeDestroy() {
260+
this.debounceRefreshCurrentConversation.clear?.()
259261
if (!getCurrentUser()) {
260262
EventBus.$off('should-refresh-conversations', this.debounceRefreshCurrentConversation)
261263
}
@@ -479,6 +481,8 @@ export default {
479481
},
480482

481483
async mounted() {
484+
this.debounceRefreshCurrentConversation = debounce(this.refreshCurrentConversation, 3000)
485+
482486
if (!IS_DESKTOP) {
483487
checkBrowser()
484488
}
@@ -581,12 +585,6 @@ export default {
581585
this.fetchSingleConversation(this.token)
582586
},
583587

584-
debounceRefreshCurrentConversation: debounce(function() {
585-
if (!this.isRefreshingCurrentConversation) {
586-
this.refreshCurrentConversation()
587-
}
588-
}, 3000),
589-
590588
changeWindowVisibility() {
591589
this.$store.dispatch('setWindowVisibility', !document.hidden)
592590
if (this.windowIsVisible) {
@@ -655,6 +653,9 @@ export default {
655653
},
656654

657655
async fetchSingleConversation(token) {
656+
if (this.isRefreshingCurrentConversation) {
657+
return
658+
}
658659
this.isRefreshingCurrentConversation = true
659660

660661
try {

‎src/components/AdminSettings/AllowedGroups.vue

+12-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
track-by="id"
5555
label="displayname"
5656
no-wrap
57-
@search-change="searchGroup" />
57+
@search-change="debounceSearchGroup" />
5858

5959
<NcButton type="primary"
6060
:disabled="loading"
@@ -84,7 +84,7 @@
8484
track-by="id"
8585
label="displayname"
8686
no-wrap
87-
@search-change="searchGroup" />
87+
@search-change="debounceSearchGroup" />
8888

8989
<NcButton type="primary"
9090
:disabled="loading"
@@ -155,6 +155,8 @@ export default {
155155

156156
startCallOptions,
157157
startCalls: startCallOptions[0],
158+
159+
debounceSearchGroup: () => {},
158160
}
159161
},
160162

@@ -183,11 +185,16 @@ export default {
183185
})
184186
this.loading = false
185187

186-
this.searchGroup('')
188+
this.debounceSearchGroup = debounce(this.searchGroup, 500)
189+
this.debounceSearchGroup('')
190+
},
191+
192+
beforeDestroy() {
193+
this.debounceSearchGroup.clear?.()
187194
},
188195

189196
methods: {
190-
searchGroup: debounce(async function(query) {
197+
async searchGroup(query) {
191198
this.loadingGroups = true
192199
try {
193200
const response = await axios.get(generateOcsUrl('cloud/groups/details'), {
@@ -203,7 +210,7 @@ export default {
203210
} finally {
204211
this.loadingGroups = false
205212
}
206-
}, 500),
213+
},
207214

208215
saveAllowedGroups() {
209216
this.loading = true

‎src/components/AdminSettings/RecordingServers.vue

+6-4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export default {
143143
loading: false,
144144
saved: false,
145145
recordingConsentSelected: loadState('spreed', 'recording_consent').toString(),
146+
debounceUpdateServers: () => {},
146147
}
147148
},
148149

@@ -158,12 +159,17 @@ export default {
158159
},
159160

160161
beforeMount() {
162+
this.debounceUpdateServers = debounce(this.updateServers, 1000)
161163
const state = loadState('spreed', 'recording_servers')
162164
this.servers = state.servers
163165
this.secret = state.secret
164166
this.uploadLimit = parseInt(state.uploadLimit, 10)
165167
},
166168

169+
beforeDestroy() {
170+
this.debounceUpdateServers.clear?.()
171+
},
172+
167173
methods: {
168174
removeServer(index) {
169175
this.servers.splice(index, 1)
@@ -182,10 +188,6 @@ export default {
182188
this.debounceUpdateServers()
183189
},
184190

185-
debounceUpdateServers: debounce(function() {
186-
this.updateServers()
187-
}, 1000),
188-
189191
async updateServers() {
190192
this.loading = true
191193

‎src/components/AdminSettings/SIPBridge.vue

+10-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
track-by="id"
5757
label="displayname"
5858
no-wrap
59-
@search-change="searchGroup" />
59+
@search-change="debounceSearchGroup" />
6060
<p class="settings-hint settings-hint--after-select">
6161
{{ t('spreed', 'Only users of the following groups can enable SIP in conversations they moderate') }}
6262
</p>
@@ -137,6 +137,7 @@ export default {
137137
dialOutEnabled: false,
138138
currentSetup: {},
139139
dialOutSupported: false,
140+
debounceSearchGroup: () => {},
140141
}
141142
},
142143

@@ -150,6 +151,7 @@ export default {
150151
},
151152

152153
mounted() {
154+
this.debounceSearchGroup = debounce(this.searchGroup, 500)
153155
this.loading = true
154156
this.groups = loadState('spreed', 'sip_bridge_groups').sort(function(a, b) {
155157
return a.displayname.localeCompare(b.displayname)
@@ -158,16 +160,20 @@ export default {
158160
this.dialInInfo = loadState('spreed', 'sip_bridge_dialin_info')
159161
this.dialOutEnabled = loadState('spreed', 'sip_bridge_dialout')
160162
this.sharedSecret = loadState('spreed', 'sip_bridge_shared_secret')
161-
this.searchGroup('')
163+
this.debounceSearchGroup('')
162164
this.loading = false
163165
this.saveCurrentSetup()
164166
const signaling = loadState('spreed', 'signaling_servers')
165167
this.showForm = signaling.servers.length > 0
166168
this.isDialoutSupported()
167169
},
168170

171+
beforeDestroy() {
172+
this.debounceSearchGroup.clear?.()
173+
},
174+
169175
methods: {
170-
searchGroup: debounce(async function(query) {
176+
async searchGroup(query) {
171177
this.loadingGroups = true
172178
try {
173179
const response = await axios.get(generateOcsUrl('cloud/groups/details'), {
@@ -183,7 +189,7 @@ export default {
183189
} finally {
184190
this.loadingGroups = false
185191
}
186-
}, 500),
192+
},
187193

188194
saveCurrentSetup() {
189195
this.currentSetup = {

‎src/components/AdminSettings/SignalingServers.vue

+6-4
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,22 @@ export default {
122122
saved: false,
123123
isCacheConfigured: loadState('spreed', 'has_cache_configured'),
124124
isClusteredMode: loadState('spreed', 'signaling_mode') === SIGNALING.MODE.CLUSTER_CONVERSATION,
125+
debounceUpdateServers: () => {},
125126
}
126127
},
127128

128129
beforeMount() {
130+
this.debounceUpdateServers = debounce(this.updateServers, 1000)
129131
const state = loadState('spreed', 'signaling_servers')
130132
this.servers = state.servers
131133
this.secret = state.secret
132134
this.hideWarning = state.hideWarning
133135
},
134136

137+
beforeDestroy() {
138+
this.debounceUpdateServers.clear?.()
139+
},
140+
135141
methods: {
136142
removeServer(index) {
137143
this.servers.splice(index, 1)
@@ -163,10 +169,6 @@ export default {
163169
this.debounceUpdateServers()
164170
},
165171

166-
debounceUpdateServers: debounce(function() {
167-
this.updateServers()
168-
}, 1000),
169-
170172
async updateServers() {
171173
this.loading = true
172174

‎src/components/AdminSettings/StunServers.vue

+6-4
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,18 @@ export default {
8484
hasInternetConnection: true,
8585
loading: false,
8686
saved: false,
87+
debounceUpdateServers: () => {},
8788
}
8889
},
8990

9091
beforeMount() {
9192
this.servers = loadState('spreed', 'stun_servers')
9293
this.hasInternetConnection = loadState('spreed', 'has_internet_connection')
94+
this.debounceUpdateServers = debounce(this.updateServers, 1000)
95+
},
96+
97+
beforeDestroy() {
98+
this.debounceUpdateServers.clear?.()
9399
},
94100

95101
methods: {
@@ -111,10 +117,6 @@ export default {
111117
}
112118
},
113119

114-
debounceUpdateServers: debounce(function() {
115-
this.updateServers()
116-
}, 1000),
117-
118120
async updateServers() {
119121
this.loading = true
120122
const servers = []

‎src/components/AdminSettings/TurnServer.vue

+6-4
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export default {
164164
testing: false,
165165
testingError: false,
166166
testingSuccess: false,
167+
debounceTestServer: () => {},
167168
}
168169
},
169170

@@ -210,16 +211,17 @@ export default {
210211
},
211212

212213
mounted() {
214+
this.debounceTestServer = debounce(this.testServer, 1000)
213215
this.testing = false
214216
this.testingError = false
215217
this.testingSuccess = false
216218
},
217219

218-
methods: {
219-
debounceTestServer: debounce(function() {
220-
this.testServer()
221-
}, 1000),
220+
beforeDestroy() {
221+
this.debounceTestServer.clear?.()
222+
},
222223

224+
methods: {
223225
testServer() {
224226
this.testing = true
225227
this.testingError = false

‎src/components/AdminSettings/TurnServers.vue

+6-4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export default {
8888
servers: [],
8989
loading: false,
9090
saved: false,
91+
debounceUpdateServers: () => {},
9192
}
9293
},
9394

@@ -100,9 +101,14 @@ export default {
100101
},
101102

102103
beforeMount() {
104+
this.debounceUpdateServers = debounce(this.updateServers, 1000)
103105
this.servers = loadState('spreed', 'turn_servers')
104106
},
105107

108+
beforeDestroy() {
109+
this.debounceUpdateServers.clear?.()
110+
},
111+
106112
methods: {
107113
removeServer(index) {
108114
this.servers.splice(index, 1)
@@ -118,10 +124,6 @@ export default {
118124
})
119125
},
120126

121-
debounceUpdateServers: debounce(function() {
122-
this.updateServers()
123-
}, 1000),
124-
125127
async updateServers() {
126128
const servers = []
127129

‎src/components/CallView/CallView.vue

+5-2
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ export default {
250250
callParticipantCollection,
251251
isBackgroundBlurred: true,
252252
showPresenterOverlay: true,
253+
debounceFetchPeers: () => {},
253254
}
254255
},
255256
computed: {
@@ -493,6 +494,7 @@ export default {
493494
this.isBackgroundBlurred = BrowserStorage.getItem('background-blurred') !== 'false'
494495
},
495496
mounted() {
497+
this.debounceFetchPeers = debounce(this.fetchPeers, 1500)
496498
EventBus.$on('refresh-peer-list', this.debounceFetchPeers)
497499

498500
callParticipantCollection.on('remove', this._lowerHandWhenParticipantLeaves)
@@ -501,6 +503,7 @@ export default {
501503
subscribe('set-background-blurred', this.setBackgroundBlurred)
502504
},
503505
beforeDestroy() {
506+
this.debounceFetchPeers.clear?.()
504507
EventBus.$off('refresh-peer-list', this.debounceFetchPeers)
505508

506509
callParticipantCollection.off('remove', this._lowerHandWhenParticipantLeaves)
@@ -719,7 +722,7 @@ export default {
719722
this.$store.dispatch('startPresentation')
720723
},
721724

722-
debounceFetchPeers: debounce(async function() {
725+
async fetchPeers() {
723726
// The recording participant does not have a Nextcloud session, so
724727
// it can not fetch the peers. This should not be a problem, as all
725728
// the needed data for the recording should be (eventually)
@@ -743,7 +746,7 @@ export default {
743746
// Just means guests have no name, so don't error …
744747
console.error(exception)
745748
}
746-
}, 1500),
749+
},
747750

748751
adjustSimulcastQuality() {
749752
this.callParticipantModels.forEach(callParticipantModel => {

‎src/components/CallView/Grid/Grid.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ export default {
304304
showVideoOverlay: true,
305305
// Timer for the videos bottom bar
306306
showVideoOverlayTimer: null,
307+
debounceMakeGrid: () => {},
307308
}
308309
},
309310

@@ -546,13 +547,15 @@ export default {
546547

547548
// bind event handlers to the `handleResize` method
548549
mounted() {
550+
this.debounceMakeGrid = debounce(this.makeGrid, 200)
549551
window.addEventListener('resize', this.handleResize)
550552
subscribe('navigation-toggled', this.handleResize)
551553
this.makeGrid()
552554

553555
window.OCA.Talk.gridDebugInformation = this.gridDebugInformation
554556
},
555557
beforeDestroy() {
558+
this.debounceMakeGrid.clear?.()
556559
window.OCA.Talk.gridDebugInformation = () => console.debug('Not in a call')
557560

558561
window.removeEventListener('resize', this.handleResize)
@@ -672,7 +675,7 @@ export default {
672675
// currently if the user is not on the 'first page', upon resize the
673676
// current position in the videos array is lost (first element
674677
// in the grid goes back to be first video)
675-
debounce(this.makeGrid, 200)
678+
this.debounceMakeGrid()
676679
},
677680

678681
// Find the right size if the grid in rows and columns (we already know
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Please sign in to comment.