mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Add compile log rule deltas to the compile-log-entries
event (#19169)
GitOrigin-RevId: 976736ecacbb79ef9c91c4861952a7af8532190e
This commit is contained in:
parent
e89cf3cddc
commit
9a8b76c24f
3 changed files with 63 additions and 3 deletions
|
@ -188,6 +188,26 @@ export const buildRuleCounts = (entries = []) => {
|
||||||
return counts
|
return counts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const buildRuleDeltas = (ruleCounts, previousRuleCounts) => {
|
||||||
|
const counts = {}
|
||||||
|
|
||||||
|
// keys that are defined in the current log entries
|
||||||
|
for (const [key, value] of Object.entries(ruleCounts)) {
|
||||||
|
const previousValue = previousRuleCounts[key] ?? 0
|
||||||
|
counts[`delta_${key}`] = value - previousValue
|
||||||
|
}
|
||||||
|
|
||||||
|
// keys that are no longer defined in the current log entries
|
||||||
|
for (const [key, value] of Object.entries(previousRuleCounts)) {
|
||||||
|
if (!(key in counts)) {
|
||||||
|
counts[key] = 0
|
||||||
|
counts[`delta_${key}`] = -value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return counts
|
||||||
|
}
|
||||||
|
|
||||||
function buildURL(file, pdfDownloadDomain) {
|
function buildURL(file, pdfDownloadDomain) {
|
||||||
if (file.build && pdfDownloadDomain) {
|
if (file.build && pdfDownloadDomain) {
|
||||||
// Downloads from the compiles domain must include a build id.
|
// Downloads from the compiles domain must include a build id.
|
||||||
|
|
|
@ -68,6 +68,7 @@ export const DetachCompileProvider: FC = ({ children }) => {
|
||||||
setChangedAt: _setChangedAt,
|
setChangedAt: _setChangedAt,
|
||||||
clearCache: _clearCache,
|
clearCache: _clearCache,
|
||||||
syncToEntry: _syncToEntry,
|
syncToEntry: _syncToEntry,
|
||||||
|
recordAction: _recordAction,
|
||||||
} = localCompileContext
|
} = localCompileContext
|
||||||
|
|
||||||
const [animateCompileDropdownArrow] = useDetachStateWatcher(
|
const [animateCompileDropdownArrow] = useDetachStateWatcher(
|
||||||
|
@ -363,6 +364,13 @@ export const DetachCompileProvider: FC = ({ children }) => {
|
||||||
'detacher'
|
'detacher'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const recordAction = useDetachAction(
|
||||||
|
'record-action',
|
||||||
|
_recordAction,
|
||||||
|
'detached',
|
||||||
|
'detacher'
|
||||||
|
)
|
||||||
|
|
||||||
useCompileTriggers(startCompile, setChangedAt)
|
useCompileTriggers(startCompile, setChangedAt)
|
||||||
useLogEvents(setShowLogs)
|
useLogEvents(setShowLogs)
|
||||||
|
|
||||||
|
@ -420,6 +428,7 @@ export const DetachCompileProvider: FC = ({ children }) => {
|
||||||
setChangedAt,
|
setChangedAt,
|
||||||
cleanupCompileResult,
|
cleanupCompileResult,
|
||||||
syncToEntry,
|
syncToEntry,
|
||||||
|
recordAction,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
animateCompileDropdownArrow,
|
animateCompileDropdownArrow,
|
||||||
|
@ -472,6 +481,7 @@ export const DetachCompileProvider: FC = ({ children }) => {
|
||||||
setChangedAt,
|
setChangedAt,
|
||||||
cleanupCompileResult,
|
cleanupCompileResult,
|
||||||
syncToEntry,
|
syncToEntry,
|
||||||
|
recordAction,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import {
|
||||||
import {
|
import {
|
||||||
buildLogEntryAnnotations,
|
buildLogEntryAnnotations,
|
||||||
buildRuleCounts,
|
buildRuleCounts,
|
||||||
|
buildRuleDeltas,
|
||||||
handleLogFiles,
|
handleLogFiles,
|
||||||
handleOutputFiles,
|
handleOutputFiles,
|
||||||
} from '../../features/pdf-preview/util/output-files'
|
} from '../../features/pdf-preview/util/output-files'
|
||||||
|
@ -97,6 +98,7 @@ export type CompileContext = {
|
||||||
setChangedAt: (value: any) => void
|
setChangedAt: (value: any) => void
|
||||||
clearCache: () => void
|
clearCache: () => void
|
||||||
syncToEntry: (value: any, keepCurrentView?: boolean) => void
|
syncToEntry: (value: any, keepCurrentView?: boolean) => void
|
||||||
|
recordAction: (action: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const LocalCompileContext = createContext<CompileContext | undefined>(
|
export const LocalCompileContext = createContext<CompileContext | undefined>(
|
||||||
|
@ -113,7 +115,7 @@ export const LocalCompileProvider: FC = ({ children }) => {
|
||||||
|
|
||||||
const { pdfPreviewOpen } = useLayoutContext()
|
const { pdfPreviewOpen } = useLayoutContext()
|
||||||
|
|
||||||
const { features, alphaProgram } = useUserContext()
|
const { features, alphaProgram, labsProgram } = useUserContext()
|
||||||
|
|
||||||
const { fileTreeData } = useFileTreeData()
|
const { fileTreeData } = useFileTreeData()
|
||||||
const { findEntityByPath } = useFileTreePathContext()
|
const { findEntityByPath } = useFileTreePathContext()
|
||||||
|
@ -351,12 +353,23 @@ export const LocalCompileProvider: FC = ({ children }) => {
|
||||||
|
|
||||||
const hasCompileLogsEvents = useFeatureFlag('compile-log-events')
|
const hasCompileLogsEvents = useFeatureFlag('compile-log-events')
|
||||||
|
|
||||||
|
// compare log entry counts with the previous compile, and record actions between compiles
|
||||||
|
// these are refs rather than state so they don't trigger the effect to run
|
||||||
|
const previousRuleCountsRef = useRef<Record<string, number> | null>(null)
|
||||||
|
const recordedActionsRef = useRef<Record<string, boolean>>({})
|
||||||
|
const recordAction = useCallback((action: string) => {
|
||||||
|
recordedActionsRef.current[action] = true
|
||||||
|
}, [])
|
||||||
|
|
||||||
// handle the data returned from a compile request
|
// handle the data returned from a compile request
|
||||||
// note: this should _only_ run when `data` changes,
|
// note: this should _only_ run when `data` changes,
|
||||||
// the other dependencies must all be static
|
// the other dependencies must all be static
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const abortController = new AbortController()
|
const abortController = new AbortController()
|
||||||
|
|
||||||
|
const recordedActions = recordedActionsRef.current
|
||||||
|
recordedActionsRef.current = {}
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
if (data.clsiServerId) {
|
if (data.clsiServerId) {
|
||||||
setClsiServerId(data.clsiServerId) // set in scope, for PdfSynctexController
|
setClsiServerId(data.clsiServerId) // set in scope, for PdfSynctexController
|
||||||
|
@ -413,13 +426,26 @@ export const LocalCompileProvider: FC = ({ children }) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasCompileLogsEvents) {
|
if (hasCompileLogsEvents || labsProgram) {
|
||||||
|
const ruleCounts = buildRuleCounts(
|
||||||
|
result.logEntries.all
|
||||||
|
) as Record<string, number>
|
||||||
|
|
||||||
|
const previousRuleCounts = previousRuleCountsRef.current
|
||||||
|
previousRuleCountsRef.current = ruleCounts
|
||||||
|
|
||||||
|
const ruleDeltas = previousRuleCounts
|
||||||
|
? buildRuleDeltas(ruleCounts, previousRuleCounts)
|
||||||
|
: {}
|
||||||
|
|
||||||
sendMB('compile-log-entries', {
|
sendMB('compile-log-entries', {
|
||||||
status: data.status,
|
status: data.status,
|
||||||
stopOnFirstError: data.options.stopOnFirstError,
|
stopOnFirstError: data.options.stopOnFirstError,
|
||||||
isAutoCompileOnLoad: !!data.options.isAutoCompileOnLoad,
|
isAutoCompileOnLoad: !!data.options.isAutoCompileOnLoad,
|
||||||
isAutoCompileOnChange: !!data.options.isAutoCompileOnChange,
|
isAutoCompileOnChange: !!data.options.isAutoCompileOnChange,
|
||||||
...buildRuleCounts(result.logEntries.all),
|
...recordedActions,
|
||||||
|
...ruleCounts,
|
||||||
|
...ruleDeltas,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -492,6 +518,8 @@ export const LocalCompileProvider: FC = ({ children }) => {
|
||||||
data,
|
data,
|
||||||
ide,
|
ide,
|
||||||
alphaProgram,
|
alphaProgram,
|
||||||
|
labsProgram,
|
||||||
|
features,
|
||||||
hasCompileLogsEvents,
|
hasCompileLogsEvents,
|
||||||
hasPremiumCompile,
|
hasPremiumCompile,
|
||||||
isProjectOwner,
|
isProjectOwner,
|
||||||
|
@ -664,6 +692,7 @@ export const LocalCompileProvider: FC = ({ children }) => {
|
||||||
setChangedAt,
|
setChangedAt,
|
||||||
cleanupCompileResult,
|
cleanupCompileResult,
|
||||||
syncToEntry,
|
syncToEntry,
|
||||||
|
recordAction,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
animateCompileDropdownArrow,
|
animateCompileDropdownArrow,
|
||||||
|
@ -715,6 +744,7 @@ export const LocalCompileProvider: FC = ({ children }) => {
|
||||||
setShowLogs,
|
setShowLogs,
|
||||||
toggleLogs,
|
toggleLogs,
|
||||||
syncToEntry,
|
syncToEntry,
|
||||||
|
recordAction,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue