mirror of
https://github.com/AJaySi/ALwrity.git
synced 2026-04-26 09:25:55 +03:00
[PR #410] [MERGED] Extract usage tracking helpers and refactor UsageTrackingService #713
Labels
No labels
AI Content Agents
AI Content Strategy
AI Content planning
AI Marketing Tools
AI SEO
AI personalization
AI writer
ALwrity Copi-lot
Alwrity web search
Anthropic
DeepSeek
Gemini AI
Integration
LLM
OnBoarding
OnBoarding
RAG knowledgebase Memory
bug
documentation
enhancement
good first issue
help wanted
invalid
openai
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/ALwrity#713
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/AJaySi/ALwrity/pull/410
Author: @AJaySi
Created: 3/12/2026
Status: ✅ Merged
Merged: 3/12/2026
Merged by: @AJaySi
Base:
main← Head:codex/refactor-usage-tracking-service-for-better-error-handling-90ieb9📝 Commits (1)
ad1756aExtract usage trends and reset logic into usage_tracking_helpers📊 Changes
5 files changed (+573 additions, -469 deletions)
View changed files
➕
backend/services/subscription/usage_tracking_helpers/__init__.py(+29 -0)➕
backend/services/subscription/usage_tracking_helpers/usage_reset_helpers.py(+73 -0)➕
backend/services/subscription/usage_tracking_helpers/usage_stats_helpers.py(+250 -0)➕
backend/services/subscription/usage_tracking_helpers/usage_trends_helpers.py(+171 -0)📝
backend/services/subscription/usage_tracking_service.py(+50 -469)📄 Description
Motivation
UsageTrackingServiceinto focused helper modules to improve readability and maintainability.Description
backend/services/subscription/usage_tracking_helperswith__init__.pyexporting the helper API.usage_reset_helpers.reset_usage_summary_countersto encapsulate summary reset behavior and replaced inline reset logic inUsageTrackingService.reset_current_billing_periodwith a call toreset_usage_summary_counters.usage_stats_helpersprovidingbuild_default_usage_percentages,build_empty_usage_response,build_provider_breakdown,calculate_final_total_cost, andmaybe_persist_reconciled_coststo handle provider cost resolution, percentage calculations, and optional DB persistence of reconciled costs, and replaced the verbose inlined code inget_user_usage_statswith calls to these helpers.usage_trends_helpersprovidingbuild_billing_periods,query_usage_summaries,self_heal_summaries_from_logs, andbuild_usage_trends_response, and refactoredget_usage_trendsto use these helpers for period construction, summary queries, self-healing from logs, and response assembly.ValueErrorcheck inget_user_usage_statswhenuser_idis missing and adjusted imports inusage_tracking_service.pyto use the new helper functions.Testing
Codex Task
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.