Unable to update 33k records, and system becomes unresponsive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-06-2024 05:57 AM
Hi,
I have a UI action called "Pause Site ID". Activating this UI action triggers a script include containing the necessary code. This code retrieves the specified Site ID and locates all associated accounts. It then updates certain fields for each account sequentially. In instances where a Site ID is linked to approximately 33,000 records, the update process takes about 8 minutes, causing the system to become unresponsive during this time.
Sample code:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2024 05:34 AM
I think you should use [updateMultiple]. Other than that...
- Index Fields: Ensure that the u_site_id field in the customer_account table is indexed. This improves the efficiency of data retrieval for your query.
- Consider Querying for Specific Fields: If you only need to update specific fields like u_pause_lifecycle and u_pause_un_pause, use ga.addQuery('fields', 'u_site_id,u_pause_lifecycle,u_pause_un_pause'); to retrieve only those fields.
- Batch Processing:
Instead of updating all records at once, split the job into batches. This could be done by limiting the number of records retrieved and processed in each cycle, reducing the overall load.
var limit = 1000; // Number of records to process at a time
var offset = 0;
while (true) {
var gr = new GlideRecord('customer_account');
gr.addQuery("u_site_id", site_id);
gr.addQuery("u_account_type", accounttype);
gr.setLimit(limit);
gr.setOffset(offset);
gr.query();
if (!gr.hasNext()) {
break;
}
while (gr.next()) {
gr.u_pause_lifecycle = true;
gr.u_pause_un_pause = true;
gr.update();
}
offset += limit;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2024 07:54 AM
Thank you Hiroshi. I will just give it a try. I will let you know.