Skip to content

Add availability index for efficient timeframe queries#24

Open
datengraben wants to merge 1 commit into
masterfrom
claude/create-availability-table-9KNcq
Open

Add availability index for efficient timeframe queries#24
datengraben wants to merge 1 commit into
masterfrom
claude/create-availability-table-9KNcq

Conversation

@datengraben

Copy link
Copy Markdown
Owner

Summary

Introduces a new availability index system to enable efficient querying of timeframes by location, item, and date range. This addresses performance concerns when checking availability across multiple dimensions.

Key Changes

  • New AvailabilityIndex repository class (src/Repository/AvailabilityIndex.php):

    • Creates three denormalized database tables: cb_availability_index (main index), cb_timeframe_locations (location junction), and cb_timeframe_items (item junction)
    • Provides upsertTimeframe() to insert/update index entries with validation (type checking, status filtering, location/item requirements)
    • Implements getByLocationAndItemAndDateRange() for efficient range queries with optional type and status filtering
    • Includes cleanup methods: deleteByTimeframeId(), removeLocation(), removeItem()
    • Provides rebuildFromAllTimeframes() for paginated index rebuilding during upgrades
  • Plugin activation and lifecycle hooks (src/Plugin.php):

    • Initializes index tables during plugin activation
    • Syncs index on timeframe/booking save via wp_insert_post hook (priority 12)
    • Removes index entries on post deletion and trashing
    • Re-indexes on post restoration (untrash)
    • Cleans up location/item references when they're deleted
  • Timeframe batch updates (src/Wordpress/CustomPostType/Timeframe.php):

    • Updates updateAllTimeframes() to sync index entries for bulk operations
  • Upgrade system integration (src/Service/Upgrade.php):

    • Registers rebuildFromAllTimeframes() as a paginated upgrade task for version 2.11.0

Implementation Details

  • Uses database transactions for atomic upserts to maintain consistency
  • Validates timeframe eligibility (allowed types, non-trashed status, has location/item assignments)
  • Supports date range queries with NULL end dates (open-ended timeframes)
  • Includes comprehensive PHPCS suppressions for direct database queries
  • Gracefully handles errors during index operations to prevent blocking post saves

https://claude.ai/code/session_01ECQBUo5Q5HHzuinoWerH8g

Introduces three new MySQL tables (cb_availability_index,
cb_timeframe_locations, cb_timeframe_items) that index timeframe
date ranges and their many-to-many location/item relationships,
replacing LIKE-on-serialised-array scans with indexed integer JOINs.

Write-side sync is wired into wp_insert_post (priority 12, after
manageTimeframeMeta at 11), before_delete_post, wp_trash_post,
untrash_post, and location/item hard-deletion hooks. The
updateAllTimeframes() path (triggered when a location or item is
added/renamed/deleted) also re-upserts affected holiday/repair
timeframes. A paginated AJAX upgrade task backfills existing posts.

https://claude.ai/code/session_01ECQBUo5Q5HHzuinoWerH8g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants