Skip to content

Commit

Permalink
Purge CDN caches for modified files
Browse files Browse the repository at this point in the history
I'm pretty sure it used to happend automatically on files sync before,
but apparently it's no longer the case.

Fixes #18

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Mar 10, 2019
1 parent e293707 commit e464045
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions files/management/commands/import_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from bs4 import BeautifulSoup
from files.utils import read_sum
import codecs
from pmaweb.cdn import purge_files_cdn


def glob_downloads(prefix=''):
Expand Down Expand Up @@ -131,6 +132,8 @@ def process_snapshots(self, path):
prefix='phpMyAdmin-' + version,
force=True,
)
if modified:
purge_files_cdn([d.__unicode__() for d in release.download_set.all()])

def handle(self, *args, **options):
self.process_releases(os.path.join(settings.FILES_PATH, 'phpMyAdmin'))
Expand Down
14 changes: 14 additions & 0 deletions pmaweb/cdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ def purge_cdn(*pages):
return perform(URL, data)


def purge_files_cdn(*pages):
"""Purges page on CDN"""
if not settings.CDN_PASSWORD:
return
data = [
('login', settings.CDN_LOGIN),
('passwd', settings.CDN_PASSWORD),
('cdn_id', settings.FILES_CDN_ID),
]
for page in pages:
data.append(('url[]', page))
return perform(URL, data)


def purge_all_cdn():
"""Purges all pages on CDN"""
if not settings.CDN_PASSWORD:
Expand Down
1 change: 1 addition & 0 deletions pmaweb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
CDN_LOGIN = 'admins@phpmyadmin.net'
CDN_PASSWORD = ''
CDN_ID = '41205'
FILES_CDN_ID = '40483'

DOCKERHUB_TOKEN = None

Expand Down

0 comments on commit e464045

Please sign in to comment.