-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Store Pageviews in DB #6121
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
Store Pageviews in DB #6121
Changes from 20 commits
0998e8a
3e8a99a
f5c82cf
e1e954c
9b03012
152aff0
f389476
1717cfc
a19823f
af056c8
a1d0a9b
82b3182
415a3b3
2073a82
b263c1b
3ec59dc
108fd5f
ddc96d9
8da0f93
d0e1317
3946398
b06d599
11eb6ac
95e7ee7
67d4885
9cb2310
3ce38c8
46747b0
7e5a1f0
b530bbc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.24 on 2019-09-18 06:11 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('builds', '0010_add-description-field-to-automation-rule'), | ||
('projects', '0044_auto_20190703_1300'), | ||
('search', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='PageView', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('path', models.CharField(max_length=4096)), | ||
('view_count', models.PositiveIntegerField(default=1)), | ||
('date', models.DateField()), | ||
('project', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='page_views', to='projects.Project')), | ||
('version', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='page_views', to='builds.Version', verbose_name='Version')), | ||
], | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
from readthedocs.builds.models import Version | ||
from readthedocs.projects.models import Project | ||
from readthedocs.search.models import SearchQuery | ||
from readthedocs.search.models import SearchQuery, PageView | ||
from readthedocs.worker import app | ||
from .utils import _get_index, _get_document | ||
|
||
|
@@ -212,3 +212,27 @@ def record_search_query(project_slug, version_slug, query, total_results, time_s | |
) | ||
obj.created = time | ||
obj.save() | ||
|
||
|
||
@app.task(queue='web') | ||
def increase_page_view_count(project_slug, version_slug, path): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if running this as a task is actually a good deal slower then running it in the footer itself? We already have the Project & Version object in the footer, and not we're adding additional queries for them here. They should be fast queries, but definitely additional load. I guess the proper solution is to cache these lookups, which we can do later if it's an issue. |
||
today_date = timezone.now().date() | ||
page_view_obj = PageView.objects.filter( | ||
project__slug=project_slug, | ||
version__slug=version_slug, | ||
path=path, | ||
date=today_date, | ||
).first() | ||
|
||
if page_view_obj: | ||
page_view_obj.view_count += 1 | ||
davidfischer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
page_view_obj.save() | ||
else: | ||
project = Project.objects.get(slug=project_slug) | ||
version = Version.objects.get(project=project, slug=version_slug) | ||
PageView.objects.create( | ||
project=project, | ||
version=version, | ||
path=path, | ||
date=today_date, | ||
) | ||
davidfischer marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
This should likely not default to
index
, no? If we don't have apage
, we probably shouldn't be storing anything, or some other string likertd-unknown-page
, notindex
.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.
I haven't seen any real examples where the page parameter is blank. It is
index
for the root and even with the dirhtml builder it uses the subdirectory name. I'll add a simpleif page_slug
check.