-
-
Couldn't load subscription status.
- Fork 238
Fixed mismatch between page views in bottom left widget and homepage stats #4653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughTemplate now requests site-wide page view data by passing Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Template as page_stats.html
participant Tag as get_page_views
participant DB as IP table
Note over Template,Tag: Widget requests site-wide views (url_path = None)
Template->>Tag: get_page_views(None, days=30)
Tag->>DB: queryset: filter(created__date__range = start_day..end_day)
alt url_path provided
Tag->>DB: add filter(path__icontains = url_path)
end
Tag->>DB: values(created__date) -> annotate(total_views=Sum(count)) -> order_by(created__date)
DB-->>Tag: daily aggregated counts
Tag-->>Template: return JSON view_counts_dict
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro Knowledge base: Disabled due to 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
website/templatetags/custom_tags.py (2)
103-109: Cache the site-wide aggregation to avoid a heavy query on every page render.The widget appears on all pages; without caching this will re-aggregate frequently. Add a short TTL cache keyed by scope and days.
Example (outside this hunk):
from django.core.cache import cache cache_key = f"pageviews:{(url_path or 'all')}:{days}:{end_day.isoformat()}" cached = cache.get(cache_key) if cached is not None: return cached # ...build view_counts_dict... json_data = json.dumps(view_counts_dict) cache.set(cache_key, json_data, 300) # 5 minutes return json_data
112-115: Optional: use TruncDate for database-agnostic grouping.This avoids backend-specific “__date” extraction quirks.
Example:
from django.db.models.functions import TruncDate daily_views = ( queryset .annotate(day=TruncDate("created")) .values("day") .annotate(total_views=models.Sum("count")) .order_by("day") ) # and read entry["day"] downstream
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting
📒 Files selected for processing (2)
website/templates/includes/page_stats.html(1 hunks)website/templatetags/custom_tags.py(1 hunks)
🔇 Additional comments (1)
website/templates/includes/page_stats.html (1)
4-4: Manually verify homepage uses identical 30-day window. I didn’t find a separate homepage calculation; ensure the homepage template callsget_page_views(None, 30)(last 30 calendar days, inclusive).
|
Hey @DonnieBLT could you please review this PR ! |
fixes: #4567
Summary by CodeRabbit