Skip to content

Commit 6841f40

Browse files
authored
Merge pull request #173 from pythonkr/devdev
apply #171
2 parents 6447d76 + 91164b4 commit 6841f40

File tree

5 files changed

+45
-17
lines changed

5 files changed

+45
-17
lines changed

.github/workflows/deploy_on_dev.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: ['3.10']
14+
python-version: ["3.10"]
1515

1616
steps:
17-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v4
1818
#- uses: psf/black@stable
1919
# with:
2020
# options: "--check --verbose"
2121

2222
- name: Set up Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v2
23+
uses: actions/setup-python@v5
2424
with:
2525
python-version: ${{ matrix.python-version }}
2626

@@ -75,7 +75,6 @@ jobs:
7575
sparse-checkout: |
7676
${{ steps.info.outputs.repository_name }}/zappa_settings.json
7777
- run: mv secret_envs/${{ steps.info.outputs.repository_name }}/zappa_settings.json ./zappa_settings.json && rm -rf secret_envs
78-
7978
# - name: Test with Django Test
8079
# run: |
8180
# source ./zappa-env/bin/activate
@@ -87,7 +86,7 @@ jobs:
8786
# pytest .
8887

8988
- name: Configure AWS Credentials
90-
uses: aws-actions/configure-aws-credentials@v1
89+
uses: aws-actions/configure-aws-credentials@v4
9190
with:
9291
aws-access-key-id: ${{ secrets.PYCON_DEV_2023_AWS_KEY }}
9392
aws-secret-access-key: ${{ secrets.PYCON_DEV_2023_AWS_SECRET }}

.github/workflows/deploy_on_prod.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: ['3.10']
14+
python-version: ["3.10"]
1515

1616
steps:
17-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v4
1818
#- uses: psf/black@stable
1919
# with:
2020
# options: "--check --verbose"
2121

2222
- name: Set up Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v2
23+
uses: actions/setup-python@v5
2424
with:
2525
python-version: ${{ matrix.python-version }}
2626

@@ -75,7 +75,6 @@ jobs:
7575
sparse-checkout: |
7676
${{ steps.info.outputs.repository_name }}/zappa_settings.json
7777
- run: mv secret_envs/${{ steps.info.outputs.repository_name }}/zappa_settings.json ./zappa_settings.json && rm -rf secret_envs
78-
7978
# - name: Test with Django Test
8079
# run: |
8180
# source ./zappa-env/bin/activate
@@ -87,7 +86,7 @@ jobs:
8786
# pytest .
8887

8988
- name: Configure AWS Credentials
90-
uses: aws-actions/configure-aws-credentials@v1
89+
uses: aws-actions/configure-aws-credentials@v4
9190
with:
9291
aws-access-key-id: ${{ secrets.PYCON_DEV_2023_AWS_KEY }}
9392
aws-secret-access-key: ${{ secrets.PYCON_DEV_2023_AWS_SECRET }}

.github/workflows/pull-request-merge-precondition.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
python-version: ['3.10']
15+
python-version: ["3.10"]
1616

1717
steps:
18-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
1919
with:
2020
persist-credentials: true # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
2121
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo

pyconkr/settings.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,16 @@
219219
"PREPROCESSING_HOOKS": ["pyconkr.openapi.preprocessing_filter_spec"],
220220
}
221221

222+
223+
# cache for django localmem
224+
# https://docs.djangoproject.com/en/5.1/topics/cache/#local-memory-caching
225+
CACHES = {
226+
"default": {
227+
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
228+
"LOCATION": "pyconkr-api-v2",
229+
}
230+
}
231+
222232
# CORS_ALLOW_ALL_ORIGINS = True
223233
CORS_ORIGIN_WHITELIST = (
224234
"https://2023.pycon.kr",

session/viewsets.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from django.conf import settings
2+
from django.utils.decorators import method_decorator
3+
from django.views.decorators.cache import cache_page
24
from drf_spectacular.utils import OpenApiExample, OpenApiResponse, extend_schema
35
from rest_framework.permissions import IsAuthenticatedOrReadOnly
46
from rest_framework.response import Response
@@ -28,14 +30,24 @@ def get_queryset(self):
2830
200: OpenApiResponse(
2931
response=str,
3032
examples=[
31-
OpenApiExample(name="2023년 세션 목록", value=SessionListSerializer(many=True)),
32-
OpenApiExample(name="2024년 이후 세션 목록 (Pretalx)", value=PretalxSessionSerializer(many=True)),
33+
OpenApiExample(
34+
name="2023년 세션 목록", value=SessionListSerializer(many=True)
35+
),
36+
OpenApiExample(
37+
name="2024년 이후 세션 목록 (Pretalx)",
38+
value=PretalxSessionSerializer(many=True),
39+
),
3340
],
3441
),
3542
},
3643
)
44+
# cache list about 30 minutes
45+
@method_decorator(cache_page(60 * 30))
3746
def list(self, request, *args, **kwargs) -> Response:
38-
if request.version == 2023 or request.version not in settings.PRETALX.EVENT_NAME:
47+
if (
48+
request.version == 2023
49+
or request.version not in settings.PRETALX.EVENT_NAME
50+
):
3951
return super().list(request, *args, **kwargs)
4052

4153
pretalx_event_name = settings.PRETALX.EVENT_NAME[request.version]
@@ -52,13 +64,21 @@ def list(self, request, *args, **kwargs) -> Response:
5264
response=str,
5365
examples=[
5466
OpenApiExample(name="2023년 세션 상세", value=SessionSerializer()),
55-
OpenApiExample(name="2024년 이후 세션 상세 (Pretalx)", value=PretalxSessionSerializer()),
67+
OpenApiExample(
68+
name="2024년 이후 세션 상세 (Pretalx)",
69+
value=PretalxSessionSerializer(),
70+
),
5671
],
5772
),
5873
},
5974
)
75+
# cache each about 30 minutes
76+
@method_decorator(cache_page(60 * 30))
6077
def retrieve(self, request, *args, **kwargs) -> Response:
61-
if request.version == 2023 or request.version not in settings.PRETALX.EVENT_NAME:
78+
if (
79+
request.version == 2023
80+
or request.version not in settings.PRETALX.EVENT_NAME
81+
):
6282
return super().retrieve(request, *args, **kwargs)
6383

6484
pretalx_event_name = settings.PRETALX.EVENT_NAME[request.version]

0 commit comments

Comments
 (0)