diff --git a/.github/workflows/deploy_on_dev.yml b/.github/workflows/deploy_on_dev.yml index 1d5d469..346a694 100644 --- a/.github/workflows/deploy_on_dev.yml +++ b/.github/workflows/deploy_on_dev.yml @@ -11,16 +11,16 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.10'] + python-version: ["3.10"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 #- uses: psf/black@stable # with: # options: "--check --verbose" - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} @@ -75,7 +75,6 @@ jobs: sparse-checkout: | ${{ steps.info.outputs.repository_name }}/zappa_settings.json - run: mv secret_envs/${{ steps.info.outputs.repository_name }}/zappa_settings.json ./zappa_settings.json && rm -rf secret_envs - # - name: Test with Django Test # run: | # source ./zappa-env/bin/activate @@ -87,7 +86,7 @@ jobs: # pytest . - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.PYCON_DEV_2023_AWS_KEY }} aws-secret-access-key: ${{ secrets.PYCON_DEV_2023_AWS_SECRET }} diff --git a/.github/workflows/deploy_on_prod.yml b/.github/workflows/deploy_on_prod.yml index 9ceaf9e..309d79a 100644 --- a/.github/workflows/deploy_on_prod.yml +++ b/.github/workflows/deploy_on_prod.yml @@ -11,16 +11,16 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.10'] + python-version: ["3.10"] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 #- uses: psf/black@stable # with: # options: "--check --verbose" - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} @@ -75,7 +75,6 @@ jobs: sparse-checkout: | ${{ steps.info.outputs.repository_name }}/zappa_settings.json - run: mv secret_envs/${{ steps.info.outputs.repository_name }}/zappa_settings.json ./zappa_settings.json && rm -rf secret_envs - # - name: Test with Django Test # run: | # source ./zappa-env/bin/activate @@ -87,7 +86,7 @@ jobs: # pytest . - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.PYCON_DEV_2023_AWS_KEY }} aws-secret-access-key: ${{ secrets.PYCON_DEV_2023_AWS_SECRET }} diff --git a/.github/workflows/pull-request-merge-precondition.yml b/.github/workflows/pull-request-merge-precondition.yml index cca8937..7632c59 100644 --- a/.github/workflows/pull-request-merge-precondition.yml +++ b/.github/workflows/pull-request-merge-precondition.yml @@ -12,10 +12,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.10'] + python-version: ["3.10"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: persist-credentials: true # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token fetch-depth: 0 # otherwise, you will failed to push refs to dest repo diff --git a/pyconkr/settings.py b/pyconkr/settings.py index 92481f0..26b722e 100644 --- a/pyconkr/settings.py +++ b/pyconkr/settings.py @@ -219,6 +219,16 @@ "PREPROCESSING_HOOKS": ["pyconkr.openapi.preprocessing_filter_spec"], } + +# cache for django localmem +# https://docs.djangoproject.com/en/5.1/topics/cache/#local-memory-caching +CACHES = { + "default": { + "BACKEND": "django.core.cache.backends.locmem.LocMemCache", + "LOCATION": "pyconkr-api-v2", + } +} + # CORS_ALLOW_ALL_ORIGINS = True CORS_ORIGIN_WHITELIST = ( "https://2023.pycon.kr", diff --git a/session/viewsets.py b/session/viewsets.py index 9ef57c4..b806d5a 100644 --- a/session/viewsets.py +++ b/session/viewsets.py @@ -1,4 +1,6 @@ from django.conf import settings +from django.utils.decorators import method_decorator +from django.views.decorators.cache import cache_page from drf_spectacular.utils import OpenApiExample, OpenApiResponse, extend_schema from rest_framework.permissions import IsAuthenticatedOrReadOnly from rest_framework.response import Response @@ -28,14 +30,24 @@ def get_queryset(self): 200: OpenApiResponse( response=str, examples=[ - OpenApiExample(name="2023년 세션 목록", value=SessionListSerializer(many=True)), - OpenApiExample(name="2024년 이후 세션 목록 (Pretalx)", value=PretalxSessionSerializer(many=True)), + OpenApiExample( + name="2023년 세션 목록", value=SessionListSerializer(many=True) + ), + OpenApiExample( + name="2024년 이후 세션 목록 (Pretalx)", + value=PretalxSessionSerializer(many=True), + ), ], ), }, ) + # cache list about 30 minutes + @method_decorator(cache_page(60 * 30)) def list(self, request, *args, **kwargs) -> Response: - if request.version == 2023 or request.version not in settings.PRETALX.EVENT_NAME: + if ( + request.version == 2023 + or request.version not in settings.PRETALX.EVENT_NAME + ): return super().list(request, *args, **kwargs) pretalx_event_name = settings.PRETALX.EVENT_NAME[request.version] @@ -52,13 +64,21 @@ def list(self, request, *args, **kwargs) -> Response: response=str, examples=[ OpenApiExample(name="2023년 세션 상세", value=SessionSerializer()), - OpenApiExample(name="2024년 이후 세션 상세 (Pretalx)", value=PretalxSessionSerializer()), + OpenApiExample( + name="2024년 이후 세션 상세 (Pretalx)", + value=PretalxSessionSerializer(), + ), ], ), }, ) + # cache each about 30 minutes + @method_decorator(cache_page(60 * 30)) def retrieve(self, request, *args, **kwargs) -> Response: - if request.version == 2023 or request.version not in settings.PRETALX.EVENT_NAME: + if ( + request.version == 2023 + or request.version not in settings.PRETALX.EVENT_NAME + ): return super().retrieve(request, *args, **kwargs) pretalx_event_name = settings.PRETALX.EVENT_NAME[request.version]