mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
Adding project PNG optimization check to compile analytics (#35925)
* feat: adding in check for if the project could have had a png optimized as part of the compile-result-backend event * feat: updating using new compile metrics to filter for only eligible project compiles * move projectHasUnconvertedPngs to stats * add e2e test for projectHasUnconvertedPngs * add unit tests for compile-with-optimizable-pngs analytics event --------- Co-authored-by: Brian Gough <brian.gough@overleaf.com> GitOrigin-RevId: 97e9d184420c34fc1d3e9f6cfe63f6b916f0202f
This commit is contained in:
committed by
Copybot
co-authored by
Brian Gough
parent
405b675740
commit
35ba44f22b
@@ -166,9 +166,10 @@ describe('CompileController', function () {
|
||||
vi.doMock(
|
||||
'../../../../app/src/Features/Analytics/AnalyticsManager',
|
||||
() => ({
|
||||
default: {
|
||||
default: (ctx.AnalyticsManager = {
|
||||
recordEventForSession: sinon.stub(),
|
||||
},
|
||||
recordEventForUserInBackground: sinon.stub(),
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
@@ -435,6 +436,83 @@ describe('CompileController', function () {
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('compile-with-optimizable-pngs analytics event', function () {
|
||||
it('records the event when the project has an unconverted png', async function (ctx) {
|
||||
ctx.CompileManager.promises.compile.resolves({
|
||||
status: 'success',
|
||||
outputFiles: [],
|
||||
stats: {
|
||||
'include-image-all': 3,
|
||||
projectHasUnconvertedPngs: 1,
|
||||
},
|
||||
timings: { 'include-image-all': 123 },
|
||||
})
|
||||
await ctx.CompileController.compile(ctx.req, ctx.res, ctx.next)
|
||||
expect(
|
||||
ctx.AnalyticsManager.recordEventForUserInBackground
|
||||
).to.have.been.calledWith(
|
||||
ctx.user_id,
|
||||
'compile-with-optimizable-pngs',
|
||||
{
|
||||
projectId: ctx.projectId,
|
||||
optimizedPngCount: 0,
|
||||
optimizedImageInclusionTime: 0,
|
||||
totalImages: 3,
|
||||
totalImageInclusionTime: 123,
|
||||
isPng2pdf: false,
|
||||
compiler: undefined,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('records the event when the compile included optimised pngs', async function (ctx) {
|
||||
ctx.CompileManager.promises.compile.resolves({
|
||||
status: 'success',
|
||||
outputFiles: [],
|
||||
stats: {
|
||||
'include-image-optimised': 2,
|
||||
'include-image-all': 5,
|
||||
projectHasUnconvertedPngs: 0,
|
||||
},
|
||||
timings: { 'include-image-optimised': 12, 'include-image-all': 34 },
|
||||
})
|
||||
await ctx.CompileController.compile(ctx.req, ctx.res, ctx.next)
|
||||
expect(
|
||||
ctx.AnalyticsManager.recordEventForUserInBackground
|
||||
).to.have.been.calledWith(
|
||||
ctx.user_id,
|
||||
'compile-with-optimizable-pngs',
|
||||
{
|
||||
projectId: ctx.projectId,
|
||||
optimizedPngCount: 2,
|
||||
optimizedImageInclusionTime: 12,
|
||||
totalImages: 5,
|
||||
totalImageInclusionTime: 34,
|
||||
isPng2pdf: false,
|
||||
compiler: undefined,
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
it('does not record the event when there are no optimizable pngs', async function (ctx) {
|
||||
ctx.CompileManager.promises.compile.resolves({
|
||||
status: 'success',
|
||||
outputFiles: [],
|
||||
stats: { 'include-image-all': 3, projectHasUnconvertedPngs: 0 },
|
||||
timings: {},
|
||||
})
|
||||
await ctx.CompileController.compile(ctx.req, ctx.res, ctx.next)
|
||||
expect(ctx.AnalyticsManager.recordEventForUserInBackground).to.not.have
|
||||
.been.called
|
||||
})
|
||||
|
||||
it('does not record the event when stats are absent', async function (ctx) {
|
||||
await ctx.CompileController.compile(ctx.req, ctx.res, ctx.next)
|
||||
expect(ctx.AnalyticsManager.recordEventForUserInBackground).to.not.have
|
||||
.been.called
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('compileSubmission', function () {
|
||||
|
||||
Reference in New Issue
Block a user