Skip to content

Commit 7e4a12a

Browse files
committed
Added refresh timer for counter
1 parent 26fd2d0 commit 7e4a12a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

zerobin/default_settings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@
5353
USER = None
5454
GROUP = None
5555

56-
# Display a tiny counter for pastes created
56+
# Display a tiny counter for pastes created.
5757
# Be carreful if your site have to many pastes this can hurt your hard drive performances.
58+
# Refresh counter interval. Default to every minute after a paste.
5859
DISPLAY_COUNTER = True
60+
REFRESH_COUNTER = 60 * 1
5961

6062
# Names/links to insert in the menu bar.
6163
# Any link with "mailto:" will be escaped to prevent spam

zerobin/routes.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929
app = Bottle()
3030
GLOBAL_CONTEXT = {
3131
'settings': settings,
32-
'pastes_count': get_pastes_count()
32+
'pastes_count': get_pastes_count(),
33+
'refresh_counter': datetime.now()
3334
}
34-
35+
3536

3637
@app.route('/')
3738
@view('home')
@@ -66,8 +67,17 @@ def create_paste():
6667
paste = Paste(expiration=expiration, content=content)
6768
paste.save()
6869

70+
# display counter
6971
if settings.DISPLAY_COUNTER:
72+
73+
#increment paste counter
7074
paste.increment_counter()
75+
76+
# if refresh time elapsed pick up new counter value
77+
if GLOBAL_CONTEXT['refresh_counter'] + timedelta(seconds=settings.REFRESH_COUNTER) < datetime.now():
78+
GLOBAL_CONTEXT['pastes_count'] = get_pastes_count()
79+
GLOBAL_CONTEXT['refresh_counter'] = datetime.now()
80+
7181

7282
return {'status': 'ok',
7383
'paste': paste.uuid}

0 commit comments

Comments
 (0)