- 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

@@ -10,8 +10,9 @@ ENABLE_PUSHNOTIFICATION=1
DIRECTORY_SERVER=/var/www/nodejs_piuchebuono_server
SERVERDIR_WEBSITE=/var/www/piuchebuono.app
PORT_APP1="0"
DOMAIN=mongodb://localhost:32001/
DOMAIN_AUTH=mongodb://{username}:{password}@127.0.0.1:32001/
DOMAIN_OFF=mongodb://localhost:32001/
DOMAIN_AUTH_OLD=mongodb://{username}:{password}@127.0.0.1:32001/
DOMAIN_AUTH=mongodb://{username}:{password}@127.0.0.1:27030/
AUTH_MONGODB=1
AUTH_DB_PASSING=1
MONGODB_USER=admin

View File

@@ -7,8 +7,9 @@ ENABLE_PUSHNOTIFICATION=1
DIRECTORY_SERVER=/var/www/nodejs_riso_server
SERVERDIR_WEBSITE=/var/www/riso.app
PORT_APP1="0"
DOMAIN=mongodb://localhost:32015/
DOMAIN_AUTH=mongodb://{username}:{password}@127.0.0.1:32015/
DOMAIN_OFF=mongodb://localhost:32015/
DOMAIN_AUTH_OLD=mongodb://{username}:{password}@127.0.0.1:32015/
DOMAIN_AUTH=mongodb://{username}:{password}@127.0.0.1:27030/
AUTH_MONGODB=1
AUTH_DB_PASSING=1
MONGODB_USER=admin

View File

@@ -26,9 +26,6 @@ if [[ $risposta == "Y" || $risposta == "y" ]]; then
ENV_FILE=".env.prod.riso"
ENV_OUT=".env.production"
#ENV_FILE=".env.prod.pcb"
#ENV_OUT=".env.production"
# Array di cartelle e file da sincronizzare
SYNC_ITEMS=(
"css"

View File

@@ -443,4 +443,24 @@ Mer 12/03 ORE 21:30: [<b>Circuito RIS Italia</b>]: Inviate Monete da surya1977 a
Saldi:
surya1977: 34.20 RIS]
Giovannifruttadisicilia: 458.50 RIS]
Giovannifruttadisicilia: 458.50 RIS]
Gio 13/03 ORE 17:44: [<b>Circuito RIS Italia</b>]: Inviate Monete da surya1977 a PiuCheBuono(GaseBottega) 1 RIS [causale: AAA]
Saldi:
surya1977: 33.20 RIS]
PiuCheBuono(GaseBottega): -65.50 RIS]
Gio 13/03 ORE 17:45: [<b>Circuito RIS Italia</b>]: Inviate Monete da surya1977 a PiuCheBuono(GaseBottega) 3.2 RIS [causale: GGG]
Saldi:
surya1977: 30.00 RIS]
PiuCheBuono(GaseBottega): -62.30 RIS]
Gio 13/03 ORE 18:17: [<b>Circuito RIS Italia</b>]: Inviate Monete da surya1977 a pontiUmani 2 RIS [causale: bbb]
Saldi:
surya1977: 28.00 RIS]
pontiUmani: 2.00 RIS]
Gio 13/03 ORE 18:18: [<b>Circuito RIS Italia</b>]: Inviate Monete da surya1977 a GruppoYurta 2 RIS [causale: ggg]
Saldi:
surya1977: 26.00 RIS]
GruppoYurta: 2.00 RIS]

View File

@@ -33,8 +33,6 @@ const authenticate = async (req, res, next) => {
//const idapp = getIdApp(req);
try {
console.log(' ### Authenticate: token', !!token);
const ris = await User.findByToken(token, access, true, false);
if (ris && ris.user && !!ris.user.deleted) {
if (ris.user.deleted)
@@ -50,7 +48,6 @@ const authenticate = async (req, res, next) => {
}
if (!!ris.user) {
console.log(' AUTH 2) ');
// crea una funzione per aggiornare il lasttimeonline e useragent
// Save last time online
const myuser = await User.updateLastTimeAndUserAgent(ris.user._id, req.get('User-Agent'));
@@ -59,7 +56,6 @@ const authenticate = async (req, res, next) => {
// req.refreshToken = refreshToken;
req.access = access;
console.log(' AUTH 3) NEXT... ');
next(); // Esegui il codice successivo
}
} catch (e) {
@@ -146,7 +142,7 @@ const authenticate_noerror = async (req, res, next) => {
try {
const token = req.header('x-auth');
const refreshToken = req.header('x-refrtok');
console.log(' ### Authenticate_noerror: token', !!token);
// console.log(' ### Authenticate_noerror: token', !!token);
if (!token) {
req.user = null;
@@ -173,7 +169,7 @@ const authenticate_noerror = async (req, res, next) => {
return res.status(server_constants.RIS_CODE_HTTP_FORBIDDEN_TOKEN_EXPIRED).send();
}
console.log(' ## NEXT ! AVANTI...');
// console.log(' ## NEXT ! AVANTI...');
next();
} catch (e) {
console.error('Errore nel middleware di autenticazione:', e);
@@ -187,7 +183,7 @@ const authenticate_noerror_WithUser = async (req, res, next) => {
try {
const token = req.header('x-auth');
const refreshToken = req.header('x-refrtok');
console.log(' ### authenticate_noerror_WithUser: token', !!token);
// console.log(' ### authenticate_noerror_WithUser: token', !!token);
if (!token) {
req.user = null;
@@ -229,7 +225,7 @@ const authenticate_noerror_WithUserLean = async (req, res, next) => {
try {
const token = req.header('x-auth');
const refreshToken = req.header('x-refrtok');
console.log(' ### authenticate_noerror_WithUserLean: token', !!token);
// console.log(' ### authenticate_noerror_WithUserLean: token', !!token);
if (!token) {
req.user = null;

View File

@@ -753,9 +753,11 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
let user = null;
let decoded;
const start = process.hrtime.bigint();
const start_jwt = process.hrtime.bigint();
if (!token) return { user, code };
try {
decoded = jwt.verify(token, process.env.SIGNCODE);
code = server_constants.RIS_CODE_OK;
@@ -769,9 +771,13 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
return { user: null, code };
}
const end_jwt = process.hrtime.bigint();
// console.log(` jwt.verify impiega ${Math.round(Number(end_jwt - start_jwt) / 1e6) / 1000} secondi.`);
let project = undefined;
if (withuser) {
const start_find = process.hrtime.bigint();
if (withlean) {
user = await User.findOne({
_id: decoded.smart,
@@ -793,10 +799,13 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
},
}, project);
}
const end_find = process.hrtime.bigint();
console.log(` User.findOne impiega ${Math.round(Number(end_find - start_find) / 1e6) / 1000} secondi.`);
} else {
project = { perm: 1, _id: 1, idapp: 1, username: 1, deleted: 1, aportador_solidario: 1, aportador_solidario_nome_completo: 1, 'profile.socioresidente': 1 };
const start_find = process.hrtime.bigint();
user = await User.findOne({
_id: decoded.smart,
tokens: {
@@ -806,6 +815,8 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
},
},
}, project).lean();
const end_find = process.hrtime.bigint();
// console.log(` User.findOne LEAN impiega ${Math.round(Number(end_find - start_find) / 1e6) / 1000} secondi.`);
}
if (user) {
@@ -817,8 +828,8 @@ UserSchema.statics.findByToken = async function (token, typeaccess, con_auth, wi
}
}
const end = process.hrtime.bigint();
console.log(` findByToken impiega ${Math.round(Number(end - start) / 1e6) / 1000} secondi.`);
// const end = process.hrtime.bigint();
// console.log(` findByToken impiega ${Math.round(Number(end - start) / 1e6) / 1000} secondi.`);
return { user, code };
};
@@ -6334,8 +6345,11 @@ UserSchema.statics.getMyGroupsById = async function (id) {
// cerca lo user by id e ritorna "profile.mygroups"
const ris = await User.findOne({ _id: id }, { 'profile.mygroups': 1 }).lean();
if (ris && ris.profile) {
return ris.profile.mygroups;
}
return ris;
return [];
};
UserSchema.statics.createNewSubRecord = async function (idapp, req) {
const User = this;
@@ -6414,6 +6428,7 @@ const FuncUsers = {
}
};
UserSchema.index({ 'tokens.token': 1, 'tokens.access': 1 });
module.exports = {
User, Hero, FuncUsers

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);

View File

@@ -59,9 +59,11 @@ router.post('/load', authenticate, async (req, res) => {
if (data.mycircuits) {
for (let i = 0; i < data.mycircuits.length; i++) {
const mycirc = await Circuit.findOne({ idapp, name: data.mycircuits[i].circuitname }).lean();
if (mycirc)
const mycirc = await Circuit.findOne({ idapp, name: data.mycircuits[i].name }).lean();
if (mycirc) {
data.mycircuits[i].account = await Account.getAccountByUsernameAndCircuitId(idapp, '', mycirc._id, true, true, groupname);
data.mycircuits[i].account = tools.jsonCopy(data.mycircuits[i].account);
}
}
}

View File

@@ -823,6 +823,8 @@ module.exports = {
mycities: 1,
sector: 1,
recCatGrp: 1,
mycircuits: 1,
lastdate_reqRisGroup: 1,
}
} else if (table === this.TABLES_CIRCUITS) {
proj = {

View File

@@ -1 +1 @@
1.2.15
1.2.17