mirror of
https://github.com/n8n-io/n8n.git
synced 2026-08-28 17:22:01 +08:00
perf(core): Read the poller state row once per durable poll tick (#36973)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -59,6 +59,7 @@ export {
|
||||
type PollerCursor,
|
||||
type PollLeaseFence,
|
||||
type PollerFailureState,
|
||||
type PollerFullState,
|
||||
} from './poller-state.repository';
|
||||
export { ProcessedDataRepository } from './processed-data.repository';
|
||||
export { SettingsRepository } from './settings.repository';
|
||||
|
||||
@@ -21,6 +21,10 @@ export interface PollerFailureState {
|
||||
backoffUntil: Date | null;
|
||||
}
|
||||
|
||||
export interface PollerFullState extends PollerFailureState {
|
||||
cursor: PollerCursor;
|
||||
}
|
||||
|
||||
@Service()
|
||||
export class PollerStateRepository extends BaseRepository<PollerState> {
|
||||
private readonly isPostgres: boolean;
|
||||
@@ -151,19 +155,23 @@ export class PollerStateRepository extends BaseRepository<PollerState> {
|
||||
return result.affected ?? 0;
|
||||
}
|
||||
|
||||
/** The node's failure counters, or `null` if it has no stored row. */
|
||||
async findFailureState(
|
||||
/** The node's cursor plus failure counters, or `null` if it has no stored row. */
|
||||
async findState(
|
||||
workflowId: string,
|
||||
nodeId: string,
|
||||
ctx: OperationContext = {},
|
||||
): Promise<PollerFailureState | null> {
|
||||
): Promise<PollerFullState | null> {
|
||||
const row = await this.managerFor(ctx).findOne(PollerState, {
|
||||
select: ['consecutiveErrors', 'backoffUntil'],
|
||||
select: ['cursor', 'consecutiveErrors', 'backoffUntil'],
|
||||
where: { workflowId, nodeId },
|
||||
});
|
||||
return row === null
|
||||
? null
|
||||
: { consecutiveErrors: row.consecutiveErrors, backoffUntil: row.backoffUntil };
|
||||
: {
|
||||
cursor: row.cursor,
|
||||
consecutiveErrors: row.consecutiveErrors,
|
||||
backoffUntil: row.backoffUntil,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -277,12 +277,11 @@ export class E2EController {
|
||||
@Get('/poller-state', { skipAuth: true })
|
||||
async getPollerState(req: Request<{}, {}, {}, { workflowId: string; nodeId: string }>) {
|
||||
const { workflowId, nodeId } = req.query;
|
||||
const cursor = await this.pollerStateRepository.findCursor(workflowId, nodeId);
|
||||
const failureState = await this.pollerStateRepository.findFailureState(workflowId, nodeId);
|
||||
const state = await this.pollerStateRepository.findState(workflowId, nodeId);
|
||||
return {
|
||||
cursor,
|
||||
consecutiveErrors: failureState?.consecutiveErrors ?? 0,
|
||||
backoffUntil: failureState?.backoffUntil ?? null,
|
||||
cursor: state?.cursor ?? null,
|
||||
consecutiveErrors: state?.consecutiveErrors ?? 0,
|
||||
backoffUntil: state?.backoffUntil ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -475,7 +474,7 @@ export class E2EController {
|
||||
}
|
||||
|
||||
private static coverageKey(url: string, fn: Profiler.FunctionCoverage): string {
|
||||
return `${url} | ||||