← Back to Pull requests

[17.0][FIX] hr_holidays_natural_period: avoid request unit recomputations #287

Closed
unknown closed this pull request without merging on Oct 09, 2026 14:42 UTC
View on GitHub
unknown unknown commented on Oct 09, 2026 07:16 UTC
Author

@BinhexTeam

Problem

In hr_holidays_natural_period 17.0, the natural-period duration
calculation temporarily changes hr.leave.type.request_unit through
ORM writes.

For natural-day leave types, _get_duration() temporarily changes:

  • natural_day to day

  • natural_day_half_day to half_day
  • and restores the original value after the duration has been computed.

    A similar temporary change is performed in
    hr.employee._get_consumed_leaves().

    Since hr.leave.type is a shared configuration record and
    request_unit participates in leave duration dependencies, these ORM
    writes can trigger unnecessary recomputations for leaves using the same
    leave type.

    With a significant number of leaves, this can cause an important
    performance degradation. Concurrent computations can additionally
    contend on the same hr.leave.type records.

    Upstream reference

    The same performance problem was addressed in the 18.0 branch of this
    module.

    The relevant upstream fix is:

  • 98ad08d42f632a572068cdfedc4d407ffeee6019

  • [FIX] hr_holidays_natural_period: Performance problem on number_of_days https://github.com/OCA/hr-holidays/pull/238

    The 18.0 implementation avoids using ORM writes for these temporary
    request_unit changes and uses env.cache.update_raw() instead, thus
    preventing the temporary value changes from triggering the normal ORM
    recomputation mechanism.

    The 18.0 implementation also avoids modifying the leave type again when
    it is already being processed through mod_holidays_status_ids.

    Proposed solution for 17.0

    Backport the same approach to the 17.0 implementation while preserving
    the 17.0 API and behavior.

    The change:

  • replaces the temporary ORM writes to

  • hr.leave.type.request_unit with env.cache.update_raw();
  • applies the change both in hr.leave._get_duration() and

  • hr.employee._get_consumed_leaves();
  • preserves the original request_unit value after the calculation;

  • avoids updating the cache again in _get_duration() when the leave

  • type is already being handled through mod_holidays_status_ids,
    following the guard used by the 18.0 implementation.

    This is intentionally a minimal backport. The 18.0 implementation uses
    the newer _get_durations() batch API, while 17.0 still uses the
    singleton _get_duration() API, so the complete 18.0 implementation
    cannot be applied directly to 17.0.

    Validation

    The existing hr_holidays_natural_period 17.0 test suite passes after
    the change:

  • 8 tests executed

  • 0 failures

  • 0 errors
  • The existing natural-day and natural-half-day scenarios continue to
    produce the expected duration results.

    SQL-level verification was also performed to ensure that the temporary
    duration calculations no longer generate the corresponding
    UPDATE hr_leave_type operations for changing and restoring
    request_unit.

    Diff: 353 lines (+264 / -89) across 4 files Reviewer: edescalona Review duration: 445m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 353 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.351
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #287"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.5% (MEDIUM) · Higher = larger blast radius
    42.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.8% · Safe to merge
    16.8%