@@ -5,11 +5,27 @@ import type { AppStore } from './types.js'
55import type { CompanionModules , StatsSamplePeriod } from './prisma/client.js'
66
77function formatQuery ( interval : string ) {
8- return `SELECT count(distinct uuid) users, module FROM \`module\` where ts >= date_sub(CURRENT_DATE, interval ${ interval } ) group by module;`
8+ return `
9+ SELECT
10+ km.module_name as module,
11+ COUNT(DISTINCT muls.user_id) as users
12+ FROM KnownModule km
13+ INNER JOIN ModuleUserLastSeen muls ON km.id = muls.module_id
14+ WHERE km.module_type = 'CONNECTION'
15+ AND km.module_version = ''
16+ AND muls.last_seen >= DATE_SUB(CURRENT_DATE, INTERVAL ${ interval } )
17+ GROUP BY km.module_name
18+ `
919}
1020
1121export async function runModules ( store : AppStore ) : Promise < void > {
12- const allModules : any [ ] = await store . oldDb . query ( 'SELECT module FROM `module` group by module;' )
22+ const allModules : any [ ] = await store . srcDb . query ( `
23+ SELECT module_name as module
24+ FROM KnownModule
25+ WHERE module_type = 'CONNECTION'
26+ AND module_version = ''
27+ GROUP BY module_name
28+ ` )
1329
1430 function convertModules ( stats : any [ ] , type : StatsSamplePeriod ) : Omit < CompanionModules , 'id' | 'ts' > [ ] {
1531 const statsMap = new Map < string , number > ( )
@@ -41,16 +57,16 @@ export async function runModules(store: AppStore): Promise<void> {
4157 }
4258
4359 await Promise . all ( [
44- runQuery ( 'Platforms 30day' , async ( ) => {
45- const rows = await store . oldDb . query ( formatQuery ( '30 day' ) )
60+ runQuery ( 'Modules 30day' , async ( ) => {
61+ const rows = await store . srcDb . query ( formatQuery ( '30 day' ) )
4662 await writeData ( rows , 'day30' as '30day' )
4763 } ) ,
48- runQuery ( 'Platforms 7day' , async ( ) => {
49- const rows = await store . oldDb . query ( formatQuery ( '7 day' ) )
64+ runQuery ( 'Modules 7day' , async ( ) => {
65+ const rows = await store . srcDb . query ( formatQuery ( '7 day' ) )
5066 await writeData ( rows , 'day7' as '7day' )
5167 } ) ,
52- runQuery ( 'Platforms 1day' , async ( ) => {
53- const rows = await store . oldDb . query ( formatQuery ( '24 hour' ) )
68+ runQuery ( 'Modules 1day' , async ( ) => {
69+ const rows = await store . srcDb . query ( formatQuery ( '24 hour' ) )
5470 await writeData ( rows , 'day1' as '1day' )
5571 } ) ,
5672 ] )
0 commit comments