I am facing an issue with a single page that displays rows from a table using inline vue.js script. The page fetches the list of rows on load and also fetches the table again when pusher events are received.
Additionally, there is a modal window that allows users to add new people to the table. When the user submits the form in the modal, an ajax request is made (using axios) to submit the record. This triggers an App\Events\NewQueueMember
event to Pusher which my vue app listens for, and upon receiving this event, the updateData
method is called to refresh the table.
The problem arises when the form is submitted, causing the page to become unresponsive for around 5 seconds before normal scrolling functions resume. In Chrome's Task manager, I noticed a significant increase in RAM usage and CPU consumption during this period.
I suspect there might be a memory leak issue, but I'm unsure how to tackle it. Any guidance would be greatly appreciated.
This is the form within the modal:
@csrf Customer Name Name will be displayed internally and to the customer<div class="form-group">
<label for="add-person-mobile">Mobile Number</label>
<input type="phone" class="form-control" name="phone_number" id="add-person-mobile"
v-model="addPersonForm.phone_number">
<small id="emailHelp" class="form-text text-muted">Please ensure number starts with +44 </small>
</div>
<div class="form-group">
<label for="add-person-party-size">Party Size</label>
<input type="number" class="form-control" name="party_size" id="add-person-party-size"
v-model="addPersonForm.party_size">
</div>
This is the vue.js script block on the same page:
<script>
Vue.use(VueTimeago, {
name: 'Timeago',
})
let vm = new Vue({
el: '#app',
data() {
return {
live_count: null,
queue: null,
loading: true,
errored: false,
buttons: {
add_to_queue_label: 'Add to Queue',
add_to_queue_disabled: false
},
addPersonForm: {
name: '',
phone_number: '',
party_size: ''
}
}
},
mounted() {
axios
.get(`/business/queue-live-feed`)
.then(response => {
console.log('got response data')
console.log(response.data)
this.queue = response.data.queue
this.live_count = response.data.live_count
})
.catch(error => {
console.log(error)
this.errored = true
})
.finally(() => this.loading = false);
},
methods: {
updateData: function () {
axios.get(`/business/queue-live-feed`)
.then(response => {
this.queue = response.data.queue
this.live_count = response.data.live_count
})
.catch(error => {
console.log(error)
this.errored = true
});
},
addPerson: function (event) {
console.log('calling resource...');
this.buttons.add_to_queue_disabled = true;
this.buttons.add_to_queue_label = "Adding...";
axios.post(`/business/queue/add2`, this.$data.addPersonForm)
.then(response => {
console.log('got a response!');
console.log(response.data);
})
.catch(error => {
console.error('error occurred :(')
})
.finally(() => {
console.log('method completed');
this.buttons.add_to_queue_disabled = false;
this.buttons.add_to_queue_label = "Add to Queue";
});
this.addPersonForm = {};
},
}
})
// PUSHER CODE
Pusher.logToConsole = true;
const pusher = new Pusher('{{ env('PUSHER_APP_KEY') }}', {
cluster: '{{ env('PUSHER_APP_CLUSTER') }}',
authEndpoint: '/broadcasting/auth',
auth: {
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}',
}
}
});
pusher.subscribe(`private-queue.business.{{ $business_id }}`)
.bind('App\\Events\\NewQueueMember', (data) => {
vm.updateData()
})
.bind('App\\Events\\QueueMemberKicked', (data) => {
vm.updateData()
})
.bind('App\\Events\\QueueMemberLeft', (data) => {
vm.updateData()
})
.bind('App\\Events\\QueueMemberNoShow', (data) => {
vm.updateData()
})
;
</script>
The problematic method is addPerson
, triggered upon form submission. Upon switching this.$data.addPersonForm
to an empty array, the unresponsiveness duration decreases significantly.
EDIT:
This is a sample response obtained from my /business/queue/add2
endpoint:
{guest_id: 55, queue_lane_id: 1, party_size: 2, short_id: "RIS0MRk0",…}
business: {id: 2, name: "Acme Ltd", business_type_id: 2, is_active: 1,…}
business_id: 2
created_at: "2020-09-27T23:53:11.000000Z"
customer: null
guest: {id: 55, name: "AJAX Test 29", phone_number: "+1234567890", business_id: 2,…}
guest_id: 55
id: 79
party_size: 2
queue_entry_time: "2020-09-28 00:53:11"
queue_lane_id: 1
short_id: "RIS0MRk0"
updated_at: "2020-09-27T23:53:11.000000Z"
The JSON response contains details of the created record and is not excessively large.
The above Vue script has been updated to reflect the additional method call within the then()
function under addPerson
.