Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ots
hypha
Commits
c749508b
Commit
c749508b
authored
5 years ago
by
Fredrik Jonsson
Browse files
Options
Downloads
Patches
Plain Diff
Implement cache for news feed.
parent
a7cf783e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
opentech/public/news/feeds.py
+18
-2
18 additions, 2 deletions
opentech/public/news/feeds.py
opentech/settings/base.py
+3
-0
3 additions, 0 deletions
opentech/settings/base.py
with
21 additions
and
2 deletions
opentech/public/news/feeds.py
+
18
−
2
View file @
c749508b
from
django.conf
import
settings
from
django.contrib.syndication.views
import
Feed
from
django.core.cache
import
cache
from
django.db.models.functions
import
Coalesce
from
django.http
import
Http404
...
...
@@ -14,7 +16,21 @@ class NewsFeed(Feed):
except
Site
.
DoesNotExist
:
raise
Http404
self
.
news_feed_settings
=
NewsFeedSettings
.
for_site
(
site
=
self
.
site
)
return
super
().
__call__
(
request
,
*
args
,
**
kwargs
)
cache_key
=
self
.
get_cache_key
(
*
args
,
**
kwargs
)
response
=
cache
.
get
(
cache_key
)
if
response
is
None
:
response
=
super
().
__call__
(
request
,
*
args
,
**
kwargs
)
cache
.
set
(
cache_key
,
response
,
settings
.
FEED_CACHE_TIMEOUT
)
return
response
def
get_cache_key
(
self
,
*
args
,
**
kwargs
):
tag
=
''
for
key
,
value
in
kwargs
.
items
():
tag
+=
f
"
-
{
key
}
-
{
value
}
"
return
f
"
{
self
.
__class__
.
__module__
}{
tag
}
"
def
title
(
self
):
return
self
.
news_feed_settings
.
news_title
...
...
@@ -56,7 +72,7 @@ class NewsTypeFeed(NewsFeed):
def
link
(
self
,
obj
):
news_index
=
NewsIndex
.
objects
.
live
().
public
().
first
()
if
news_index
:
return
news_index
.
full_url
+
'
?news_type={
}
'
.
format
(
obj
.
id
)
return
f
"
{
news_index
.
full_url
}
?news_type=
{
obj
.
id
}
"
return
self
.
site
.
root_url
def
items
(
self
,
obj
):
...
...
This diff is collapsed.
Click to expand it.
opentech/settings/base.py
+
3
−
0
View file @
c749508b
...
...
@@ -214,6 +214,9 @@ except ValueError:
# Set wagtail cache timeout (automatic cache refresh).
WAGTAIL_CACHE_TIMEOUT
=
CACHE_CONTROL_MAX_AGE
# Set feed cache timeout (automatic cache refresh).
FEED_CACHE_TIMEOUT
=
600
if
'
REDIS_URL
'
in
env
:
CACHES
=
{
"
default
"
:
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment