Skip to content

Commit

Permalink
Change analytics queries to run sequentially
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite committed Dec 12, 2024
1 parent 313da04 commit ed0e390
Showing 1 changed file with 37 additions and 36 deletions.
73 changes: 37 additions & 36 deletions lib/model/query/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
const config = require('config');
const { sql } = require('slonik');
const { clone } = require('ramda');
const { runSequentially } = require('../../util/promise');
const { metricsTemplate } = require('../../data/analytics');
const oidc = require('../../util/oidc');

Expand Down Expand Up @@ -557,24 +558,24 @@ JOIN submission_defs as sd
const getProjectsWithDescriptions = () => ({ all }) => all(sql`
select id as "projectId", length(trim(description)) as description_length from projects where coalesce(trim(description),'')!=''`);

const projectMetrics = () => (({ Analytics }) => Promise.all([
Analytics.countUsersPerRole(),
Analytics.countAppUsers(),
Analytics.countDeviceIds(),
Analytics.countPublicLinks(),
Analytics.countForms(),
Analytics.countFormFieldTypes(),
Analytics.countFormsEncrypted(),
Analytics.countFormsInStates(),
Analytics.countReusedFormIds(),
Analytics.countSubmissions(),
Analytics.countSubmissionReviewStates(),
Analytics.countSubmissionsEdited(),
Analytics.countSubmissionsComments(),
Analytics.countSubmissionsByUserType(),
Analytics.getProjectsWithDescriptions(),
Analytics.getDatasets(),
Analytics.getDatasetEvents()
const projectMetrics = () => (({ Analytics }) => runSequentially([
Analytics.countUsersPerRole,
Analytics.countAppUsers,
Analytics.countDeviceIds,
Analytics.countPublicLinks,
Analytics.countForms,
Analytics.countFormFieldTypes,
Analytics.countFormsEncrypted,
Analytics.countFormsInStates,
Analytics.countReusedFormIds,
Analytics.countSubmissions,
Analytics.countSubmissionReviewStates,
Analytics.countSubmissionsEdited,
Analytics.countSubmissionsComments,
Analytics.countSubmissionsByUserType,
Analytics.getProjectsWithDescriptions,
Analytics.getDatasets,
Analytics.getDatasetEvents
]).then(([ userRoles, appUsers, deviceIds, pubLinks,
forms, formGeoRepeats, formsEncrypt, formStates, reusedIds,
subs, subStates, subEdited, subComments, subUsers,
Expand Down Expand Up @@ -725,24 +726,24 @@ const projectMetrics = () => (({ Analytics }) => Promise.all([
return projArray;
}));

const previewMetrics = () => (({ Analytics }) => Promise.all([
Analytics.databaseSize(),
Analytics.encryptedProjects(),
Analytics.biggestForm(),
Analytics.countAdmins(),
Analytics.auditLogs(),
Analytics.archivedProjects(),
Analytics.countUniqueManagers(),
Analytics.countUniqueViewers(),
Analytics.countUniqueDataCollectors(),
Analytics.countClientAuditAttachments(),
Analytics.countClientAuditProcessingFailed(),
Analytics.countClientAuditRows(),
Analytics.countOfflineBranches(),
Analytics.countInterruptedBranches(),
Analytics.countSubmissionReprocess(),
Analytics.measureEntityProcessingTime(),
Analytics.projectMetrics()
const previewMetrics = () => (({ Analytics }) => runSequentially([
Analytics.databaseSize,
Analytics.encryptedProjects,
Analytics.biggestForm,
Analytics.countAdmins,
Analytics.auditLogs,
Analytics.archivedProjects,
Analytics.countUniqueManagers,
Analytics.countUniqueViewers,
Analytics.countUniqueDataCollectors,
Analytics.countClientAuditAttachments,
Analytics.countClientAuditProcessingFailed,
Analytics.countClientAuditRows,
Analytics.countOfflineBranches,
Analytics.countInterruptedBranches,
Analytics.countSubmissionReprocess,
Analytics.measureEntityProcessingTime,
Analytics.projectMetrics
]).then(([db, encrypt, bigForm, admins, audits,
archived, managers, viewers, collectors,
caAttachments, caFailures, caRows,
Expand Down

0 comments on commit ed0e390

Please sign in to comment.