[PR #431] Persist GSC comparable-window delta events and expose latest alerts retrieval #735

Open
opened 2026-03-13 21:06:25 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/AJaySi/ALwrity/pull/431
Author: @AJaySi
Created: 3/12/2026
Status: 🔄 Open

Base: mainHead: codex/implement-delta-event-processing-and-retrieval


📝 Commits (1)

  • 328a81d Add persisted GSC delta events and latest alerts retrieval

📊 Changes

4 files changed (+377 additions, -28 deletions)

View changed files

📝 backend/models/platform_insights_monitoring_models.py (+40 -0)
backend/services/analytics/opportunity_alerts_service.py (+62 -0)
📝 backend/services/analytics/platform_analytics_service.py (+24 -0)
📝 backend/services/scheduler/executors/gsc_insights_executor.py (+251 -28)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/AJaySi/ALwrity/pull/431 **Author:** [@AJaySi](https://github.com/AJaySi) **Created:** 3/12/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `codex/implement-delta-event-processing-and-retrieval` --- ### 📝 Commits (1) - [`328a81d`](https://github.com/AJaySi/ALwrity/commit/328a81d24c4788bb85bbe616458de712221bfaf6) Add persisted GSC delta events and latest alerts retrieval ### 📊 Changes **4 files changed** (+377 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `backend/models/platform_insights_monitoring_models.py` (+40 -0) ➕ `backend/services/analytics/opportunity_alerts_service.py` (+62 -0) 📝 `backend/services/analytics/platform_analytics_service.py` (+24 -0) 📝 `backend/services/scheduler/executors/gsc_insights_executor.py` (+251 -28) </details> ### 📄 Description ### 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](https://chatgpt.com/codex/tasks/task_e_69b26cc6596883288137e2bf33d37fe0) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ALwrity#735
No description provided.