Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ale
ngv
Commits
31706e46
Commit
31706e46
authored
Sep 13, 2008
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
do not cache sqlalchemy objects until we find a way of doing it correctly
parent
ad9d5b09
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
28 deletions
+8
-28
ngv_frontend/ngv_frontend/controllers/video.py
ngv_frontend/ngv_frontend/controllers/video.py
+8
-28
No files found.
ngv_frontend/ngv_frontend/controllers/video.py
View file @
31706e46
...
...
@@ -64,30 +64,17 @@ class VideoController(BaseController):
def
list
(
self
,
what
,
arg
=
None
):
"""List videos according to several criteria specified by the
'what' argument (and, eventually, the 'arg' parameter).
If the user is not logged in, the response is cached.
"""
if
what
==
'queue'
\
and
not
(
h
.
logged_in
()
and
h
.
in_group
(
'reviewers'
)):
return
'Unauthorized.'
# the full videos list is kept into cache for normal users
def
list_videos_fn
():
res
=
model
.
VideoQuery
.
query
([(
what
,
arg
)])
return
(
res
.
query
.
all
(),
res
.
title
,
res
.
count
)
if
not
h
.
logged_in
():
v_cache
=
cache
.
get_cache
(
'videos'
)
all_videos
,
c
.
title
,
num_videos
=
v_cache
.
get_value
(
'%s/%s'
%
(
what
,
arg
or
'_'
),
type
=
'memory'
,
createfunc
=
list_videos_fn
,
expiretime
=
600
)
else
:
all_videos
,
c
.
title
,
num_videos
=
list_videos_fn
()
res
=
model
.
VideoQuery
.
query
([(
what
,
arg
)])
# paginate the videos
page_num
=
int
(
request
.
params
.
get
(
'p'
,
0
))
c
.
videos
=
h
.
Page
(
all_videos
,
item_count
=
num_videos
,
res
.
query
,
item_count
=
res
.
count
,
page
=
page_num
,
items_per_page
=
10
)
c
.
title
=
res
.
title
c
.
what
=
what
c
.
arg
=
arg
c
.
page_num
=
page_num
...
...
@@ -96,22 +83,15 @@ class VideoController(BaseController):
def
rss
(
self
,
what
,
arg
=
None
):
"""Similar to list, render an RSS 2.0 feed. The caching
strategy is also simpler."""
def
list_videos_fn
():
res
=
model
.
VideoQuery
.
query
([(
what
,
arg
)])
videos
=
res
.
query
.
order_by
([
desc
(
model
.
Video
.
publication_date
)]).
limit
(
15
).
all
()
etag
=
md5
.
md5
(
u
''
.
join
([
x
.
title
for
x
in
videos
]).
encode
(
'utf-8'
)).
hexdigest
()
return
(
etag
,
videos
,
res
.
count
,
res
.
title
)
v_cache
=
cache
.
get_cache
(
'rss_videos'
)
cache_key
=
"%s/%s"
%
(
what
,
arg
or
'_'
)
etag
,
c
.
videos
,
count
,
c
.
title
=
v_cache
.
get_value
(
cache_key
,
type
=
'memory'
,
expiretime
=
900
,
createfunc
=
list_videos_fn
)
res
=
model
.
VideoQuery
.
query
([(
what
,
arg
)])
c
.
videos
=
res
.
query
.
order_by
([
desc
(
model
.
Video
.
publication_date
)]).
limit
(
15
).
all
()
c
.
title
=
rest
.
title
etag
=
md5
.
md5
(
u
''
.
join
([
x
.
title
for
x
in
videos
]).
encode
(
'utf-8'
)).
hexdigest
()
etag_cache
(
etag
)
response
.
headers
[
'Expires'
]
=
h
.
httpdate
(
datetime
.
now
()
+
timedelta
(
1
))
response
.
headers
[
'Last-Modified'
]
=
h
.
httpdate
(
c
.
videos
[
0
].
publication_date
)
response
.
headers
[
'Content-Type'
]
=
'application/rss+xml'
cache_key
=
"%s/%s"
%
(
what
,
arg
or
'_'
)
return
render
(
'video/rss.html'
,
cache_key
=
cache_key
,
cache_expire
=
900
)
@
authorize
(
permission
.
LoggedIn
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment