- fix: sistemato pagina gruppo che non si visualizzava (errore per modifica)

- fix: corretto il "Invia RIS" al gruppo.
This commit is contained in:
Surya Paolo
2025-03-13 18:19:42 +01:00
parent f32bd189dc
commit f713f66369
10 changed files with 113 additions and 31 deletions

View File

@@ -1797,17 +1797,65 @@ router.get('/loadsite/:userId/:idapp', authenticate_noerror_WithUserLean, (req,
load(req, res, '0');
});
// Funzione di test per misurare le performance di MongoDB
async function testMongoPerformance(ind, iterations = 20) {
let logString = "";
const log = (msg) => { logString += msg + "\n"; };
log(`Avvio del test ${ind} di performance MongoDB con ${iterations} iterazioni...`);
const timings = [];
for (let i = 0; i < iterations; i++) {
const start = process.hrtime();
try {
// Esegui una query semplice; sostituisci "User" con il tuo modello se necessario
if (ind === 1) {
await User.findOne({}).lean();
} else {
const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJQUk9WQU1TR0AxQSIsInNtYXJ0IjoiNjIwODAwYWRjMTI5ZDFlYmE3NjBiZWNiIiwiYWNjZXNzIjoiYXV0aCIsInVuIjoic3VyeWExOTc3IiwiaWF0IjoxNzQxODcyMzEwLCJleHAiOjE3NDE4Nzk1MTB9.SXJLmsS6EZVhaU7sUWYMnaqGpiiy8RfE9K43xTdxNuU';
await User.findByToken(token, 'auth', true, true);
}
} catch (err) {
log(`Errore nell'iterazione ${i + 1}: ${err.message}`);
}
const diff = process.hrtime(start);
const timeInSeconds = diff[0] + diff[1] / 1e9;
timings.push(timeInSeconds);
log(`Iterazione ${i + 1}: ${timeInSeconds.toFixed(3)} sec`);
}
const totalTime = timings.reduce((acc, t) => acc + t, 0);
const averageTime = totalTime / timings.length;
const minTime = Math.min(...timings);
const maxTime = Math.max(...timings);
log(`--- Risultati del test ${ind} ---`);
log(`Tempo totale: ${totalTime.toFixed(3)} sec`);
log(`Tempo medio: ${averageTime.toFixed(3)} sec`);
log(`Tempo minimo: ${minTime.toFixed(3)} sec`);
log(`Tempo massimo: ${maxTime.toFixed(3)} sec`);
return { totalTime, averageTime, minTime, maxTime, timings, log: logString };
}
// Supponendo di usare Express e di avere già definito "router"
router.get('/testpao', async (req, res) => {
try {
// Simulazione di un'operazione asincrona (es. chiamata a DB o altro)
// await new Promise(resolve => setTimeout(resolve, 2000));
res.status(200).send('OK');
let ind = req.query.ind;
let numval = req.query.numval;
const result = await testMongoPerformance(ind, numval);
res.status(200).json({ log: result.log });
} catch (error) {
console.error('Errore durante il caricamento del sito:', error);
res.status(500).json({ error: 'Errore interno del server: TEST' });
console.error("Errore nel test di performance:", error);
res.status(500).json({ error: error.message });
}
});
router.get('/loadsite/:userId/:idapp/:vers', authenticate_noerror_WithUserLean, async (req, res) => {
try {
let versionstr = req.params.vers;
@@ -1855,7 +1903,7 @@ async function measurePromises(promises) {
// Ordina le chiamate per tempo decrescente e prende le 10 più lente
const slowCalls = Object.entries(timings)
.sort(([, timeA], [, timeB]) => timeB - timeA)
.slice(0, 10)
.slice(0, 5)
.map(([key, time]) => ({ key, time }));
return { data, totalTime, slowCalls };
@@ -1864,7 +1912,7 @@ async function measurePromises(promises) {
async function load(req, res, version = '0') {
try {
console.log(' ... 1) richiesta LOAD');
// console.log(' ... 1) richiesta LOAD');
// Estrazione e validazione degli input
const userId = req.user ? req.user._id.toString() : req.params.userId || '0';
@@ -1973,7 +2021,7 @@ async function load(req, res, version = '0') {
const { data, totalTime, slowCalls } = await measurePromises(promises);
// console.log('Risultati delle promise:', data);
console.log('Tempo totale di esecuzione:', totalTime, 'secondi');
console.log('Le 10 chiamate più lente:', slowCalls);
console.log('Le 5 chiamate più lente:', slowCalls);
// Aggiornamento delle informazioni dell'utente, se presente
let myuser = req.user;
@@ -2072,7 +2120,7 @@ async function load(req, res, version = '0') {
};
}
console.log(' ... 2) load dati caricati ...');
// console.log(' ... 2) load dati caricati ...');
res.status(status).send(responseData);
} catch (e) {
console.error('Errore in load:', e);