other routes
Build and Push Docker Images / build-and-push (push) Successful in 45s

This commit is contained in:
2025-11-20 14:57:58 +01:00
parent 8ef3848f6f
commit b126c08c27
3 changed files with 434 additions and 1 deletions
+84
View File
@@ -287,6 +287,90 @@ const dbOps = {
}
},
async getCachedOutgoingCalls(url, now) {
const callsKey = `outgoing-calls:${url}`;
if (dbType === 'postgres') {
const client = await pgPool.connect();
try {
const result = await client.query(
'SELECT html FROM cache WHERE url = $1 AND expires_at > $2',
[callsKey, now]
);
if (result.rows.length > 0) {
return JSON.parse(result.rows[0].html);
}
return null;
} finally {
client.release();
}
} else {
const getCached = db.prepare('SELECT html FROM cache WHERE url = ? AND expires_at > ?');
const result = getCached.get(callsKey, now);
return result ? JSON.parse(result.html) : null;
}
},
async setCacheOutgoingCalls(url, callsData, now, expiresAt) {
const callsKey = `outgoing-calls:${url}`;
const html = JSON.stringify(callsData);
if (dbType === 'postgres') {
const client = await pgPool.connect();
try {
await client.query(
'INSERT INTO cache (url, html, created_at, expires_at) VALUES ($1, $2, $3, $4) ON CONFLICT (url) DO UPDATE SET html = $2, created_at = $3, expires_at = $4',
[callsKey, html, now, expiresAt]
);
} finally {
client.release();
}
} else {
const setCache = db.prepare('INSERT OR REPLACE INTO cache (url, html, created_at, expires_at) VALUES (?, ?, ?, ?)');
setCache.run(callsKey, html, now, expiresAt);
}
},
async getCachedResultingUrl(url, now) {
const resultingUrlKey = `resulting-url:${url}`;
if (dbType === 'postgres') {
const client = await pgPool.connect();
try {
const result = await client.query(
'SELECT html FROM cache WHERE url = $1 AND expires_at > $2',
[resultingUrlKey, now]
);
if (result.rows.length > 0) {
return JSON.parse(result.rows[0].html);
}
return null;
} finally {
client.release();
}
} else {
const getCached = db.prepare('SELECT html FROM cache WHERE url = ? AND expires_at > ?');
const result = getCached.get(resultingUrlKey, now);
return result ? JSON.parse(result.html) : null;
}
},
async setCacheResultingUrl(url, resultingUrlData, now, expiresAt) {
const resultingUrlKey = `resulting-url:${url}`;
const html = JSON.stringify(resultingUrlData);
if (dbType === 'postgres') {
const client = await pgPool.connect();
try {
await client.query(
'INSERT INTO cache (url, html, created_at, expires_at) VALUES ($1, $2, $3, $4) ON CONFLICT (url) DO UPDATE SET html = $2, created_at = $3, expires_at = $4',
[resultingUrlKey, html, now, expiresAt]
);
} finally {
client.release();
}
} else {
const setCache = db.prepare('INSERT OR REPLACE INTO cache (url, html, created_at, expires_at) VALUES (?, ?, ?, ?)');
setCache.run(resultingUrlKey, html, now, expiresAt);
}
},
async deleteExpired(now) {
if (dbType === 'postgres') {
const client = await pgPool.connect();