Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions apps/report-api/utils/reportService.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,58 @@ ORDER BY
};

export const queryRanks = async () => {
const res = await alloydb.query('SELECT rank FROM public.tech_report_ranks ORDER BY mobile_origins DESC;');
return res.rows;
try {
const res = await alloydb.query('SELECT rank FROM public.tech_report_ranks ORDER BY mobile_origins DESC;');
if (res?.rows?.length > 0) return res.rows;
} catch (err) {
console.error('AlloyDB queryRanks failed, falling back to Firestore:', err?.message || err);
}

try {
const snapshot = await firestore
.collection('ranks')
.orderBy('mobile_origins', 'desc')
.select('rank')
.get();
const data = [];
snapshot.forEach(doc => data.push(doc.data()));
if (data.length > 0) return data;
} catch (err) {
console.error('Firestore queryRanks failed:', err?.message || err);
}

return [
{ rank: 'ALL' },
{ rank: 'Top 10M' },
{ rank: 'Top 1M' },
{ rank: 'Top 100k' },
{ rank: 'Top 10k' },
{ rank: 'Top 1k' }
];
};

export const queryGeos = async () => {
const res = await alloydb.query('SELECT geo FROM public.tech_report_geos ORDER BY mobile_origins DESC;');
return res.rows;
try {
const res = await alloydb.query('SELECT geo FROM public.tech_report_geos ORDER BY mobile_origins DESC;');
if (res?.rows?.length > 0) return res.rows;
} catch (err) {
console.error('AlloyDB queryGeos failed, falling back to Firestore:', err?.message || err);
}

try {
const snapshot = await firestore
.collection('geos')
.orderBy('mobile_origins', 'desc')
.select('geo')
.get();
const data = [];
snapshot.forEach(doc => data.push(doc.data()));
if (data.length > 0) return data;
} catch (err) {
console.error('Firestore queryGeos failed:', err?.message || err);
}

return [{ geo: 'ALL' }];
};

export const queryVersions = async (params = {}) => {
Expand Down
Loading