Skip to content

Fixed : Index audits, skip empty translation audits, and fix history preview - #508

Merged
navneetkumar-pim-webkul merged 2 commits into
unopim:masterfrom
dripar-webkul:fix/audits-index-skip-empty-translation-audit-master
Jun 19, 2026
Merged

navneetkumar-pim-webkul merged 2 commits into
unopim:masterfrom
dripar-webkul:fix/audits-index-skip-empty-translation-audit-master

Conversation

@dripar-webkul

Copy link
Copy Markdown
Collaborator

Description

Creating an attribute returns a 504 on installs with a large audits table,
and viewing an attribute's History failed / showed noise.

Root cause

  • AttributeTranslation and other translatable models use HistoryTrait, so
    creating one attribute writes one audit row per active locale. The
    audit_before_insert trigger runs two queries per insert filtering by
    (tags, history_id), which was never indexed — every insert is a full table
    scan, so creation times out as audits grows.
  • Blank locales still produced empty audit rows (noise + trigger load).
  • The History version preview crashed ("Array to string conversion") on a
    created version because the old value is an empty array, and it listed
    empty/default fields (validation, regex_pattern, ai_translate).

Changes

  1. Add composite index on audits(tags, history_id) (prefix-aware, idempotent,
    MySQL + PostgreSQL). The trigger's two lookups become index lookups
    (EXPLAIN: type=ALL → type=ref, rows=1).
  2. Override OwenIt's readyForAuditing() in HistoryTrait to skip auditing a
    translatable model when all of its historyTranslatableFields are empty.
    Non-translatable models (Attribute, Product, Category, …) are unaffected.
  3. Guard AttributeHistoryPresenter::formatValue() against array (empty old)
    values so the created-version history no longer 500s.
  4. Drop history rows that are empty on both sides so the preview shows only
    meaningful changes.
  5. Add Pest tests: audits index/behaviour, the presenter, and the history
    preview across every attribute type.

Measured on ~2.1M audit rows: one attribute create dropped from ~138s to ~1.9s;
audit inserts per create dropped from 51 to 2.

How To Test This?

  1. vendor/bin/pest packages/Webkul/Admin/tests/Feature/Catalog/AttributeAuditTest.php
  2. vendor/bin/pest packages/Webkul/Admin/tests/Feature/Catalog/AttributeHistoryViewTest.php
  3. Manually: Catalog → Attributes → Create Attribute → code + type + name → Save.
    Saves quickly even on a large audits table; open the History tab → view a
    version: it renders without error and omits empty fields.
  4. SHOW INDEX FROM audits; shows audits_tags_history_id_index (tags, history_id).

Checklist

  • vendor/bin/pest passes locally (new tests — 33 passed)

  • vendor/bin/pint --test reports no style issues

  • Target branch is master

@navneetkumar-pim-webkul
navneetkumar-pim-webkul merged commit f12a48b into unopim:master Jun 19, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants