chore(server/stats): disable deprecated ServerStats (#3714)

This commit is contained in:
Iain Sproat
2024-12-19 10:32:47 +00:00
committed by GitHub
parent 25010e330c
commit 0d2af686f9
3 changed files with 27 additions and 156 deletions
@@ -1,19 +1,23 @@
import { Resolvers } from '@/modules/core/graph/generated/graphql'
import { validateScopes } from '@/modules/shared'
import {
getStreamHistoryFactory,
getCommitHistoryFactory,
getObjectHistoryFactory,
getUserHistoryFactory,
getTotalStreamCountFactory,
getTotalCommitCountFactory,
getTotalObjectCountFactory,
getTotalUserCountFactory
} from '@/modules/stats/repositories/index'
import { Roles, Scopes } from '@speckle/shared'
import { throwForNotHavingServerRole } from '@/modules/shared/authz'
import { db } from '@/db/knex'
const dummyHistory = [
{ '0': 0 },
{ '1': 0 },
{ '2': 0 },
{ '3': 0 },
{ '4': 0 },
{ '5': 0 },
{ '6': 0 },
{ '7': 0 },
{ '8': 0 },
{ '9': 0 },
{ '10': 0 },
{ '11': 0 }
]
export = {
Query: {
@@ -29,35 +33,35 @@ export = {
ServerStats: {
async totalStreamCount() {
return await getTotalStreamCountFactory({ db })()
return 0 //deprecated, returning static value
},
async totalCommitCount() {
return await getTotalCommitCountFactory({ db })()
return 0 //deprecated, returning static value
},
async totalObjectCount() {
return await getTotalObjectCountFactory({ db })()
return 0 //deprecated, returning static value
},
async totalUserCount() {
return await getTotalUserCountFactory({ db })()
return 0 //deprecated, returning static value
},
async streamHistory() {
return await getStreamHistoryFactory({ db })()
return dummyHistory //deprecated, returning static value
},
async commitHistory() {
return await getCommitHistoryFactory({ db })()
return dummyHistory //deprecated, returning static value
},
async objectHistory() {
return await getObjectHistoryFactory({ db })()
return dummyHistory //deprecated, returning static value
},
async userHistory() {
return await getUserHistoryFactory({ db })()
return dummyHistory //deprecated, returning static value
}
}
} as Resolvers
@@ -6,18 +6,6 @@ export const getTotalStreamCountFactory = (deps: { db: Knex }) => async () => {
return parseInt(result.rows[0].count)
}
export const getTotalCommitCountFactory = (deps: { db: Knex }) => async () => {
const query = 'SELECT COUNT(*) FROM commits'
const result = await deps.db.raw(query)
return parseInt(result.rows[0].count)
}
export const getTotalObjectCountFactory = (deps: { db: Knex }) => async () => {
const query = 'SELECT COUNT(*) FROM objects'
const result = await deps.db.raw(query)
return parseInt(result.rows[0].count)
}
export const getTotalUserCountFactory = (deps: { db: Knex }) => async () => {
// returns -1 for small tables, no good
// const fastQuery = "SELECT reltuples::bigint AS estimate FROM pg_catalog.pg_class WHERE relname = 'users'"
@@ -25,72 +13,3 @@ export const getTotalUserCountFactory = (deps: { db: Knex }) => async () => {
const result = await deps.db.raw(query)
return parseInt(result.rows[0].count)
}
export const getStreamHistoryFactory = (deps: { db: Knex }) => async () => {
const query = `
SELECT
DATE_TRUNC('month', streams. "createdAt") AS created_month,
COUNT(id) AS count
FROM
streams
GROUP BY
DATE_TRUNC('month', streams. "createdAt")
`
const result = (await deps.db.raw(query)) as {
rows: Array<{ created_month: Date; count: string | number }>
}
result.rows.forEach((row) => (row.count = parseInt(row.count + '')))
return result.rows
}
export const getCommitHistoryFactory = (deps: { db: Knex }) => async () => {
const query = `
SELECT
DATE_TRUNC('month', commits. "createdAt") AS created_month,
COUNT(id) AS count
FROM
commits
GROUP BY
DATE_TRUNC('month', commits. "createdAt")
`
const result = (await deps.db.raw(query)) as {
rows: Array<{ created_month: Date; count: string | number }>
}
result.rows.forEach((row) => (row.count = parseInt(row.count + '')))
return result.rows
}
export const getObjectHistoryFactory = (deps: { db: Knex }) => async () => {
const query = `
SELECT
DATE_TRUNC('month', objects. "createdAt") AS created_month,
COUNT(id) AS count
FROM
objects
GROUP BY
DATE_TRUNC('month', objects. "createdAt")
`
const result = (await deps.db.raw(query)) as {
rows: Array<{ created_month: Date; count: string | number }>
}
result.rows.forEach((row) => (row.count = parseInt(row.count + '')))
return result.rows
}
export const getUserHistoryFactory = (deps: { db: Knex }) => async () => {
const query = `
SELECT
DATE_TRUNC('month', users. "createdAt") AS created_month,
COUNT(id) AS count
FROM
users
GROUP BY
DATE_TRUNC('month', users. "createdAt")
`
const result = (await deps.db.raw(query)) as {
rows: Array<{ created_month: Date; count: string | number }>
}
result.rows.forEach((row) => (row.count = parseInt(row.count + '')))
return result.rows
}
@@ -4,13 +4,7 @@ import { beforeEachContext, initializeTestServer } from '@/test/hooks'
import { createManyObjects } from '@/test/helpers'
import {
getStreamHistoryFactory,
getCommitHistoryFactory,
getObjectHistoryFactory,
getUserHistoryFactory,
getTotalStreamCountFactory,
getTotalCommitCountFactory,
getTotalObjectCountFactory,
getTotalUserCountFactory
} from '@/modules/stats/repositories/index'
import { Scopes } from '@speckle/shared'
@@ -202,52 +196,6 @@ describe('Server stats services @stats-services', function () {
const res = await getTotalStreamCountFactory({ db })()
expect(res).to.equal(params.numStreams)
})
it('should return the total number of commits on this server', async () => {
const res = await getTotalCommitCountFactory({ db })()
expect(res).to.equal(params.numCommits)
})
it('should return the total number of objects on this server', async () => {
const res = await getTotalObjectCountFactory({ db })()
expect(res).to.equal(params.numObjects)
})
it('should return the stream creation history by month', async () => {
const res = await getStreamHistoryFactory({ db })()
expect(res).to.be.an('array')
expect(res[0]).to.have.property('count')
expect(res[0]).to.have.property('created_month')
expect(res[0].count).to.be.a('number')
expect(res[0].count).to.equal(params.numStreams)
})
it('should return the commit creation history by month', async () => {
const res = await getCommitHistoryFactory({ db })()
expect(res).to.be.an('array')
expect(res[0]).to.have.property('count')
expect(res[0]).to.have.property('created_month')
expect(res[0].count).to.be.a('number')
expect(res[0].count).to.equal(params.numCommits)
})
it('should return the object creation history by month', async () => {
const res = await getObjectHistoryFactory({ db })()
expect(res).to.be.an('array')
expect(res[0]).to.have.property('count')
expect(res[0]).to.have.property('created_month')
expect(res[0].count).to.be.a('number')
expect(res[0].count).to.equal(params.numObjects)
})
it('should return the user creation history by month', async () => {
const res = await getUserHistoryFactory({ db })()
expect(res).to.be.an('array')
expect(res[0]).to.have.property('count')
expect(res[0]).to.have.property('created_month')
expect(res[0].count).to.be.a('number')
expect(res[0].count).to.equal(params.numUsers)
})
})
describe('Server stats api @stats-api', function () {
@@ -357,10 +305,10 @@ describe('Server stats api @stats-api', function () {
expect(res.body.data.serverStats).to.have.property('commitHistory')
expect(res.body.data.serverStats).to.have.property('userHistory')
expect(res.body.data.serverStats.totalStreamCount).to.equal(params.numStreams)
expect(res.body.data.serverStats.totalCommitCount).to.equal(params.numCommits)
expect(res.body.data.serverStats.totalObjectCount).to.equal(params.numObjects)
expect(res.body.data.serverStats.totalUserCount).to.equal(params.numUsers + 2) // we're registering two extra users in the before hook
expect(res.body.data.serverStats.totalStreamCount).to.equal(0) // the endpoint is deprecated and we're now returning 0
expect(res.body.data.serverStats.totalCommitCount).to.equal(0) // the endpoint is deprecated and we're now returning 0
expect(res.body.data.serverStats.totalObjectCount).to.equal(0) // the endpoint is deprecated and we're now returning 0
expect(res.body.data.serverStats.totalUserCount).to.equal(0) // the endpoint is deprecated and we're now returning 0
expect(res.body.data.serverStats.streamHistory).to.be.an('array')
expect(res.body.data.serverStats.commitHistory).to.be.an('array')