mirror of
https://github.com/logto-io/logto.git
synced 2025-01-27 21:39:16 -05:00
refactor(core): fix dashboard queries
This commit is contained in:
parent
9c04da0ffe
commit
854e1e5751
1 changed files with 3 additions and 8 deletions
|
@ -1,6 +1,5 @@
|
|||
import type { CreateLog, Log } from '@logto/schemas';
|
||||
import { Logs } from '@logto/schemas';
|
||||
import type { LogType } from '@logto/schemas/lib/types/log-legacy.js';
|
||||
import { token, Logs } from '@logto/schemas';
|
||||
import { conditionalSql, convertToIdentifiers } from '@logto/shared';
|
||||
import { sql } from 'slonik';
|
||||
|
||||
|
@ -51,10 +50,6 @@ export const findLogs = async (limit: number, offset: number, logCondition: LogC
|
|||
|
||||
export const findLogById = buildFindEntityById<CreateLog, Log>(Logs);
|
||||
|
||||
// The active user should exchange the tokens by the authorization code (i.e. sign-in)
|
||||
// or exchange the access token, which will expire in 2 hours, by the refresh token.
|
||||
const activeUserLogTypes: LogType[] = ['CodeExchangeToken', 'RefreshTokenExchangeToken'];
|
||||
|
||||
export const getDailyActiveUserCountsByTimeInterval = async (
|
||||
startTimeExclusive: number,
|
||||
endTimeInclusive: number
|
||||
|
@ -64,7 +59,7 @@ export const getDailyActiveUserCountsByTimeInterval = async (
|
|||
from ${table}
|
||||
where ${fields.createdAt} > to_timestamp(${startTimeExclusive}::double precision / 1000)
|
||||
and ${fields.createdAt} <= to_timestamp(${endTimeInclusive}::double precision / 1000)
|
||||
and ${fields.type} in (${sql.join(activeUserLogTypes, sql`, `)})
|
||||
and ${fields.type} like ${`${token.Flow.ExchangeTokenBy}.%`}
|
||||
and ${fields.payload}->>'result' = 'Success'
|
||||
group by date(${fields.createdAt})
|
||||
`);
|
||||
|
@ -78,6 +73,6 @@ export const countActiveUsersByTimeInterval = async (
|
|||
from ${table}
|
||||
where ${fields.createdAt} > to_timestamp(${startTimeExclusive}::double precision / 1000)
|
||||
and ${fields.createdAt} <= to_timestamp(${endTimeInclusive}::double precision / 1000)
|
||||
and ${fields.type} in (${sql.join(activeUserLogTypes, sql`, `)})
|
||||
and ${fields.type} like ${`${token.Flow.ExchangeTokenBy}.%`}
|
||||
and ${fields.payload}->>'result' = 'Success'
|
||||
`);
|
||||
|
|
Loading…
Add table
Reference in a new issue