openvibers/openvibe.network Commits
T2: SUM() over bigint columns is cast back to bigint
Changes
@@@ -40,7 +40,7 @@ module.exports = function createAnalyticsRoutes(analytics, requireAuth, config,async function beaconFallback(svc, days) {try {const host = BEACON_HOSTS[svc.name]; if (!host) return null;-- const row = await analytics.db.prepare("SELECT COALESCE(SUM(hits), 0) AS n FROM frame_hits WHERE day >= substring(datetime('now', ?), 1, 10) AND (host = ? OR host LIKE ?)").get(`-${Math.min(days || 30, 365)} days`, host, '%.' + host);++ const row = await analytics.db.prepare("SELECT COALESCE(SUM(hits), 0)::bigint AS n FROM frame_hits WHERE day >= substring(datetime('now', ?), 1, 10) AND (host = ? OR host LIKE ?)").get(`-${Math.min(days || 30, 365)} days`, host, '%.' + host);return { ok: true, analytics: { summary: { total_pageviews: row.n, source: 'navbar page-view count (no service analytics)' }, realtime: {} } };} catch { return null; }}@@@ -44,7 +44,7 @@ async function getBalance(db, userId) {async function balanceAfterTx(db, tx) {const row = await db.prepare(-- 'SELECT COALESCE(SUM(delta), 0) AS bal FROM coin_transactions WHERE user_id = ? AND id <= ?'++ 'SELECT COALESCE(SUM(delta), 0)::bigint AS bal FROM coin_transactions WHERE user_id = ? AND id <= ?').get(tx.user_id, tx.id);return row.bal;}@@@ -183,7 +183,7 @@ async function summary(db, projectId, { days = 30, env = 'all', now = () => Date// Quotas (dev_quotas, staff-set): what their current window used, every environment together.const seen = new Set((await db.prepare('SELECT DISTINCT capability, unit FROM dev_usage_daily WHERE project_id = ?').all(projectId)).map((r) => `${r.capability}|${r.unit}`));-- const usedSince = db.prepare('SELECT COALESCE(SUM(quantity), 0) AS n FROM dev_usage_daily WHERE project_id = ? AND capability = ? AND unit = ? AND day >= ?');++ const usedSince = db.prepare('SELECT COALESCE(SUM(quantity), 0)::bigint AS n FROM dev_usage_daily WHERE project_id = ? AND capability = ? AND unit = ? AND day >= ?');const quotas = (await Promise.all((await db.prepare('SELECT * FROM dev_quotas WHERE project_id = ? ORDER BY capability').all(projectId)).map(async (qr) => {const cap = capabilities.get(qr.capability);const out = { capability: qr.capability, limit: qr.limit_value, window: qr.quota_window, unit: qr.unit, enforced_by: cap ? `openvibe.${cap.owner}` : null, used: null, remaining: null, window_start: null, note: null };@@@ -86,7 +86,7 @@ async function createFrameService(db, config, analytics, { privateKey = null, is// Everything else: the navbar's page-view beacon, summed per site over 7 days.let tools = rank.tools || [];try {-- const rows = await db.prepare("SELECT host, SUM(hits) AS n FROM frame_hits WHERE day >= substring(datetime('now', '-7 days'), 1, 10) GROUP BY host").all();++ const rows = await db.prepare("SELECT host, SUM(hits)::bigint AS n FROM frame_hits WHERE day >= substring(datetime('now', '-7 days'), 1, 10) GROUP BY host").all();const perSite = {}; const perTool = new Map();const { catalog } = toolsCatalog.peek();const toolOfHost = new Map();
@@ -40,7 +40,7 @@ module.exports = function createAnalyticsRoutes(analytics, requireAuth, config,
@@ -40,7 +40,7 @@ module.exports = function createAnalyticsRoutes(analytics, requireAuth, config,
async function beaconFallback(svc, days) {
async function beaconFallback(svc, days) {
try {
try {
const host = BEACON_HOSTS[svc.name]; if (!host) return null;
const host = BEACON_HOSTS[svc.name]; if (!host) return null;
- const row = await analytics.db.prepare("SELECT COALESCE(SUM(hits), 0) AS n FROM frame_hits WHERE day >= substring(datetime('now', ?), 1, 10) AND (host = ? OR host LIKE ?)").get(`-${Math.min(days || 30, 365)} days`, host, '%.' + host);
+ const row = await analytics.db.prepare("SELECT COALESCE(SUM(hits), 0)::bigint AS n FROM frame_hits WHERE day >= substring(datetime('now', ?), 1, 10) AND (host = ? OR host LIKE ?)").get(`-${Math.min(days || 30, 365)} days`, host, '%.' + host);
return { ok: true, analytics: { summary: { total_pageviews: row.n, source: 'navbar page-view count (no service analytics)' }, realtime: {} } };
return { ok: true, analytics: { summary: { total_pageviews: row.n, source: 'navbar page-view count (no service analytics)' }, realtime: {} } };
} catch { return null; }
} catch { return null; }
}
}
@@ -44,7 +44,7 @@ async function getBalance(db, userId) {
@@ -44,7 +44,7 @@ async function getBalance(db, userId) {
async function balanceAfterTx(db, tx) {
async function balanceAfterTx(db, tx) {
const row = await db.prepare(
const row = await db.prepare(
- 'SELECT COALESCE(SUM(delta), 0) AS bal FROM coin_transactions WHERE user_id = ? AND id <= ?'
+ 'SELECT COALESCE(SUM(delta), 0)::bigint AS bal FROM coin_transactions WHERE user_id = ? AND id <= ?'
).get(tx.user_id, tx.id);
).get(tx.user_id, tx.id);
return row.bal;
return row.bal;
}
}
@@ -183,7 +183,7 @@ async function summary(db, projectId, { days = 30, env = 'all', now = () => Date
@@ -183,7 +183,7 @@ async function summary(db, projectId, { days = 30, env = 'all', now = () => Date
// Quotas (dev_quotas, staff-set): what their current window used, every environment together.
// Quotas (dev_quotas, staff-set): what their current window used, every environment together.
const seen = new Set((await db.prepare('SELECT DISTINCT capability, unit FROM dev_usage_daily WHERE project_id = ?').all(projectId)).map((r) => `${r.capability}|${r.unit}`));
const seen = new Set((await db.prepare('SELECT DISTINCT capability, unit FROM dev_usage_daily WHERE project_id = ?').all(projectId)).map((r) => `${r.capability}|${r.unit}`));
- const usedSince = db.prepare('SELECT COALESCE(SUM(quantity), 0) AS n FROM dev_usage_daily WHERE project_id = ? AND capability = ? AND unit = ? AND day >= ?');
+ const usedSince = db.prepare('SELECT COALESCE(SUM(quantity), 0)::bigint AS n FROM dev_usage_daily WHERE project_id = ? AND capability = ? AND unit = ? AND day >= ?');
const quotas = (await Promise.all((await db.prepare('SELECT * FROM dev_quotas WHERE project_id = ? ORDER BY capability').all(projectId)).map(async (qr) => {
const quotas = (await Promise.all((await db.prepare('SELECT * FROM dev_quotas WHERE project_id = ? ORDER BY capability').all(projectId)).map(async (qr) => {
const cap = capabilities.get(qr.capability);
const cap = capabilities.get(qr.capability);
const out = { capability: qr.capability, limit: qr.limit_value, window: qr.quota_window, unit: qr.unit, enforced_by: cap ? `openvibe.${cap.owner}` : null, used: null, remaining: null, window_start: null, note: null };
const out = { capability: qr.capability, limit: qr.limit_value, window: qr.quota_window, unit: qr.unit, enforced_by: cap ? `openvibe.${cap.owner}` : null, used: null, remaining: null, window_start: null, note: null };
@@ -86,7 +86,7 @@ async function createFrameService(db, config, analytics, { privateKey = null, is
@@ -86,7 +86,7 @@ async function createFrameService(db, config, analytics, { privateKey = null, is
// Everything else: the navbar's page-view beacon, summed per site over 7 days.
// Everything else: the navbar's page-view beacon, summed per site over 7 days.
let tools = rank.tools || [];
let tools = rank.tools || [];
try {
try {
- const rows = await db.prepare("SELECT host, SUM(hits) AS n FROM frame_hits WHERE day >= substring(datetime('now', '-7 days'), 1, 10) GROUP BY host").all();
+ const rows = await db.prepare("SELECT host, SUM(hits)::bigint AS n FROM frame_hits WHERE day >= substring(datetime('now', '-7 days'), 1, 10) GROUP BY host").all();
const perSite = {}; const perTool = new Map();
const perSite = {}; const perTool = new Map();
const { catalog } = toolsCatalog.peek();
const { catalog } = toolsCatalog.peek();
const toolOfHost = new Map();
const toolOfHost = new Map();