Guest post proposal — Loading PrestaShop dashboard widgets in one request
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 65/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- javascript, php
- Domain
- backend, documentation
Research direction
Start by reviewing the issue’s patch for js/admin/dashboard.js and controllers/admin/AdminDashboardController.php, then check the existing refreshDashboard behavior in a PrestaShop 9.2.1 test installation. The proposed contribution is a how-to article for reproducing, applying, and verifying the batch request, including individual refresh and fallback behavior. Done means the article accurately reflects the stock files and explains the compatibility check after a core update.
Written by the indexing model from the issue text.
Description
Hi Build team,
I'd like to contribute a short how-to about speeding up the legacy Back Office dashboard in PrestaShop 9.2.1.
The default dashboard sends a separate AJAX request for each widget. In one store, profiling showed concurrent requests from the same administrator session queueing behind PHP's session lock. The existing refreshDashboard action already returns data for all dashboard widgets when called without a module parameter.
The patch uses that existing response to load the four dashboard widgets in one request. It preserves individual refreshes and retries widgets individually if the batch request fails. In eight paired runs against the same store, median time to receive all four widget responses went from 1.71 s to 0.55 s. The old path was tested with up to three concurrent requests. This measurement covers widget data loading on that store.
The article would cover how to reproduce the request pattern, verify the widgets after applying the patch, and check compatibility after a core update. I verified the example against the stock 9.2.1 files and ran JavaScript regression checks for batch loading, single-widget refresh, and fallback. Would this be a fit for Build?
PrestaShop 9.2.1 example patch
Save the diff as prestashop-9.2.1-dashboard-refresh.patch. From the root of a 9.2.1 test installation, check it with git apply --check prestashop-9.2.1-dashboard-refresh.patch and apply it with git apply prestashop-9.2.1-dashboard-refresh.patch. Open the Back Office dashboard and check that one refreshDashboard request returns the four widgets.
diff --git a/js/admin/dashboard.js b/js/admin/dashboard.js
--- a/js/admin/dashboard.js
+++ b/js/admin/dashboard.js
@@ -10,44 +10,52 @@
// read_more
function refreshDashboard(module_name, extra) {
- var module_list = [];
- this.getWidget = function(module_id) {
+ var moduleList = [];
+
+ if (module_name === false) {
+ $('.widget[id]').each(function () {
+ moduleList.push(this.id);
+ $(this).addClass('loading');
+ });
+ } else {
+ moduleList.push(module_name);
+ $('#' + module_name + ' section').addClass('loading');
+ }
+
+ function loadWidgets(moduleName) {
+ var data = { ajax: true, action: 'refreshDashboard', extra: extra };
+ if (moduleName !== false) {
+ data.module = moduleName;
+ }
+
$.ajax({
- url : dashboard_ajax_url,
- data : {
- ajax: true,
- action:'refreshDashboard',
- module: module_list[module_id],
- extra: extra
- },
+ url: dashboard_ajax_url,
+ data: data,
// Ensure to get fresh data
headers: { "cache-control": "no-cache" },
cache: false,
global: false,
dataType: 'json',
- success : function(widgets){
- for (var widget_name in widgets) {
- for (var data_type in widgets[widget_name]) {
- window[data_type](widget_name, widgets[widget_name][data_type]);
+ success: function (widgets) {
+ var names = moduleName === false ? moduleList : [moduleName];
+ names.forEach(function (widgetName) {
+ var widget = widgets && widgets[widgetName];
+ for (var dataType in widget) {
+ window[dataType](widgetName, widget[dataType]);
}
+ });
+ },
+ error: function (xhr, status) {
+ if (moduleName === false && status !== 'abort') {
+ moduleList.forEach(loadWidgets);
}
},
contentType: 'application/json'
});
- };
- if (module_name === false) {
- $('.widget').each( function () {
- module_list.push($(this).attr('id'));
- $(this).addClass('loading');
- });
- } else {
- module_list.push(module_name);
- $('#'+module_name+' section').each( function (){
- $(this).addClass('loading');
- });
- }
- for (var module_id in module_list) {
- this.getWidget(module_id);
+ }
+
+ if (moduleList.length) {
+ loadWidgets(module_name);
}
}
diff --git a/controllers/admin/AdminDashboardController.php b/controllers/admin/AdminDashboardController.php
--- a/controllers/admin/AdminDashboardController.php
+++ b/controllers/admin/AdminDashboardController.php
@@ -27,7 +27,7 @@
$this->addJS([
_PS_JS_DIR_ . 'vendor/d3.v3.min.js',
__PS_BASE_URI__ . $this->admin_webpath . '/themes/' . $this->bo_theme . '/js/vendor/nv.d3.min.js',
- _PS_JS_DIR_ . '/admin/dashboard.js',
+ _PS_JS_DIR_ . '/admin/dashboard.js?v=9.2.1-dashboard-batch.1',
]);
$this->addCSS(__PS_BASE_URI__ . $this->admin_webpath . '/themes/' . $this->bo_theme . '/css/vendor/nv.d3.css');
}
- Dominant language
- SCSS
- Stars
- 41
- Forks
- 56
- Avg merge
- 3h 37m
- Merged PRs (30d)
- 6
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PrestaShop/prestashop.github.io
-
Difficulty 3/5 1-2 days Newbie friendliness 56/100
PrestaShop/prestashop.github.io#1455 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
PrestaShop/prestashop.github.io#1118 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
PrestaShop/prestashop.github.io#672 · 1 comment · 2 reactions ·
-
SEO
Difficulty 2/5 1-3 hours Newbie friendliness 42/100
PrestaShop/prestashop.github.io#573 · 1 comment ·
All issues in PrestaShop/prestashop.github.io
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:auth-provider issue-rating: 🦞 diamond lobster no-stale P2
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
openclaw/openclaw#206303 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
[BUG] MCP resources-as-tools drops invocation context when listing templatesPossibly taken @CryoThrust claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
langchain4j/langchain4j#7320 ·
Maintainers usually reply within 1 day
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day