Skip to content

Persist GSC comparable-window delta events and expose latest alerts retrieval#431

Open
AJaySi wants to merge 1 commit intomainfrom
codex/implement-delta-event-processing-and-retrieval
Open

Persist GSC comparable-window delta events and expose latest alerts retrieval#431
AJaySi wants to merge 1 commit intomainfrom
codex/implement-delta-event-processing-and-retrieval

Conversation

@AJaySi
Copy link
Owner

@AJaySi AJaySi commented Mar 12, 2026

Motivation

  • Avoid repeated heavy per-page/query comparisons in the UI by precomputing and persisting GSC delta events for dashboard and content-strategy flows.
  • Provide a single, indexed storage surface that other services can query for recent opportunities/alerts instead of recalculating deltas on demand.
  • Support actionable classifications (decline/rise/opportunity) and severity metadata so downstream features can prioritize signals.

Description

  • Added PlatformInsightDeltaEvent model/table to persist delta events with ownership, event_type, entity_type, entity_key, comparable-window metadata, details payload, severity, and relevant indexes (backend/models/platform_insights_monitoring_models.py).
  • Enhanced GSCInsightsExecutor to fetch the current 30-day window and the prior comparable 30-day window, compute per-page and per-query deltas (clicks/impressions/CTR/position), label events using in-code thresholds (decline/rise/opportunity), and persist events to platform_insight_delta_events while deduplicating by current window (backend/services/scheduler/executors/gsc_insights_executor.py).
  • Added OpportunityAlertsService to provide a lightweight, user-scoped retrieval API for the latest persisted events with filtering by platform/site/event types (backend/services/analytics/opportunity_alerts_service.py).
  • Exposed get_latest_opportunities_alerts(...) on PlatformAnalyticsService to let UIs and analytics layers fetch precomputed events without recomputing deltas (backend/services/analytics/platform_analytics_service.py).
  • Persistence includes deterministic dedupe (delete previous rows for the same user/platform/site/current-window) and stores a full details JSON containing metrics, deltas, reasons, thresholds, and window metadata.

Testing

  • Compiled modified Python modules with python -m py_compile backend/models/platform_insights_monitoring_models.py backend/services/scheduler/executors/gsc_insights_executor.py backend/services/analytics/opportunity_alerts_service.py backend/services/analytics/platform_analytics_service.py, which succeeded without syntax errors.
  • Performed lightweight static validation by importing/compiling the changed modules (no runtime integration tests executed in this rollout).

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant