diff --git a/.env.prod.pcb b/.env.prod.pcb
index 4e1a464..d0a7a1c 100644
--- a/.env.prod.pcb
+++ b/.env.prod.pcb
@@ -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
diff --git a/.env.prod.riso b/.env.prod.riso
index 63935cd..ea784f9 100644
--- a/.env.prod.riso
+++ b/.env.prod.riso
@@ -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
diff --git a/deploynode_riso_prod.sh b/deploynode_riso_prod.sh
index 4c20a24..9be8a37 100755
--- a/deploynode_riso_prod.sh
+++ b/deploynode_riso_prod.sh
@@ -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"
diff --git a/logtrans.txt b/logtrans.txt
index 45a3a62..33dd88d 100644
--- a/logtrans.txt
+++ b/logtrans.txt
@@ -443,4 +443,24 @@ Mer 12/03 ORE 21:30: [Circuito RIS Italia]: Inviate Monete da surya1977 a
Saldi:
surya1977: 34.20 RIS]
-Giovannifruttadisicilia: 458.50 RIS]
\ No newline at end of file
+Giovannifruttadisicilia: 458.50 RIS]
+Gio 13/03 ORE 17:44: [Circuito RIS Italia]: 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: [Circuito RIS Italia]: 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: [Circuito RIS Italia]: 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: [Circuito RIS Italia]: Inviate Monete da surya1977 a GruppoYurta 2 RIS [causale: ggg]
+
+Saldi:
+surya1977: 26.00 RIS]
+GruppoYurta: 2.00 RIS]
\ No newline at end of file
diff --git a/src/server/middleware/authenticate.js b/src/server/middleware/authenticate.js
index ccd66f9..a501889 100755
--- a/src/server/middleware/authenticate.js
+++ b/src/server/middleware/authenticate.js
@@ -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;
diff --git a/src/server/models/user.js b/src/server/models/user.js
index 5d6b726..d35a094 100755
--- a/src/server/models/user.js
+++ b/src/server/models/user.js
@@ -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
diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js
index 161acd7..a68f4e0 100755
--- a/src/server/router/index_router.js
+++ b/src/server/router/index_router.js
@@ -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);
diff --git a/src/server/router/mygroups_router.js b/src/server/router/mygroups_router.js
index d7c3272..6cffac5 100755
--- a/src/server/router/mygroups_router.js
+++ b/src/server/router/mygroups_router.js
@@ -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);
+ }
}
}
diff --git a/src/server/tools/shared_nodejs.js b/src/server/tools/shared_nodejs.js
index cce1495..df7db3f 100755
--- a/src/server/tools/shared_nodejs.js
+++ b/src/server/tools/shared_nodejs.js
@@ -823,6 +823,8 @@ module.exports = {
mycities: 1,
sector: 1,
recCatGrp: 1,
+ mycircuits: 1,
+ lastdate_reqRisGroup: 1,
}
} else if (table === this.TABLES_CIRCUITS) {
proj = {
diff --git a/src/server/version.txt b/src/server/version.txt
index 05060b8..21344eb 100644
--- a/src/server/version.txt
+++ b/src/server/version.txt
@@ -1 +1 @@
-1.2.15
\ No newline at end of file
+1.2.17
\ No newline at end of file