fix: cache database username to avoid redundant API calls\n\n- Added cachedDbUsername variable to store username after first API call\n- Modified loadPricelistsDbUsername to check cache before making API request\n- Reduces unnecessary API calls when opening pricelists modal multiple times\n- Improves performance and reduces server load
This commit is contained in:
@@ -221,6 +221,7 @@ let sortDir = 'desc';
|
|||||||
let pricelistsPage = 1;
|
let pricelistsPage = 1;
|
||||||
let pricelistsCanWrite = false;
|
let pricelistsCanWrite = false;
|
||||||
let isCreatingPricelist = false;
|
let isCreatingPricelist = false;
|
||||||
|
let cachedDbUsername = null;
|
||||||
|
|
||||||
async function loadTab(tab) {
|
async function loadTab(tab) {
|
||||||
currentTab = tab;
|
currentTab = tab;
|
||||||
@@ -998,10 +999,16 @@ function renderPricelistsPagination(total, page, perPage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadPricelistsDbUsername() {
|
async function loadPricelistsDbUsername() {
|
||||||
|
if (cachedDbUsername) {
|
||||||
|
document.getElementById('pricelists-db-username').textContent = cachedDbUsername;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await fetch('/api/current-user');
|
const resp = await fetch('/api/current-user');
|
||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
document.getElementById('pricelists-db-username').textContent = data.username || 'неизвестно';
|
cachedDbUsername = data.username || 'неизвестно';
|
||||||
|
document.getElementById('pricelists-db-username').textContent = cachedDbUsername;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
document.getElementById('pricelists-db-username').textContent = 'неизвестно';
|
document.getElementById('pricelists-db-username').textContent = 'неизвестно';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user