From 4abd77d70ac3626dea343f9d562aaf55f1f6edf4 Mon Sep 17 00:00:00 2001 From: Yakser Date: Wed, 14 Feb 2024 23:18:59 +0300 Subject: [PATCH 1/5] fix required_skills serializer --- vacancy/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vacancy/serializers.py b/vacancy/serializers.py index ecc17c99..f2964057 100644 --- a/vacancy/serializers.py +++ b/vacancy/serializers.py @@ -22,7 +22,7 @@ class Meta: class VacancyDetailSerializer(serializers.ModelSerializer): project = ProjectForVacancySerializer(many=False, read_only=True) - required_skills = serializers.ListSerializer(child=serializers.CharField()) + required_skills = CustomListField(child=serializers.CharField()) class Meta: model = Vacancy From 5a99350ba6a53911528f9e8cc5ea56609ea6df9c Mon Sep 17 00:00:00 2001 From: Koshak Date: Sat, 9 Mar 2024 23:37:36 +0300 Subject: [PATCH 2/5] done --- poetry.lock | 28 +++++++++++++++++++++++++++- procollab/settings.py | 25 +++++++++++++++++++++---- projects/signals.py | 5 +++++ projects/views.py | 6 ++++++ pyproject.toml | 1 + 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/poetry.lock b/poetry.lock index 02077633..249a05c9 100644 --- a/poetry.lock +++ b/poetry.lock @@ -664,6 +664,21 @@ tzdata = {version = "*", markers = "sys_platform == \"win32\""} argon2 = ["argon2-cffi (>=19.1.0)"] bcrypt = ["bcrypt"] +[[package]] +name = "django-cacheops" +version = "7.0.2" +description = "A slick ORM cache with automatic granular event-driven invalidation for Django." +optional = false +python-versions = ">=3.7" +files = [ + {file = "django-cacheops-7.0.2.tar.gz", hash = "sha256:77a37c73d7facfc7299365ed66a12be7a487dd745dd86c1d33ca2ebfd3b32878"}, +] + +[package.dependencies] +django = ">=3.2" +funcy = ">=1.8,<3.0" +redis = ">=3.0.0" + [[package]] name = "django-cleanup" version = "6.0.0" @@ -1041,6 +1056,17 @@ files = [ {file = "frozenlist-1.4.0.tar.gz", hash = "sha256:09163bdf0b2907454042edb19f887c6d33806adc71fbd54afc14908bfdc22251"}, ] +[[package]] +name = "funcy" +version = "2.0" +description = "A fancy and practical functional tools" +optional = false +python-versions = "*" +files = [ + {file = "funcy-2.0-py2.py3-none-any.whl", hash = "sha256:53df23c8bb1651b12f095df764bfb057935d49537a56de211b098f4c79614bb0"}, + {file = "funcy-2.0.tar.gz", hash = "sha256:3963315d59d41c6f30c04bc910e10ab50a3ac4a225868bfa96feed133df075cb"}, +] + [[package]] name = "hyperlink" version = "21.0.0" @@ -2440,4 +2466,4 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "5ac8a366a6339e2db2c0d3ebfc01298bfbd5d2f86ed9e5d91da8022f2b20a1f9" +content-hash = "8ea0ee684a2f9c3e08991326a489598372c0328eb18a8795470400c3ef97750e" diff --git a/procollab/settings.py b/procollab/settings.py index 1d54ce63..410dd882 100644 --- a/procollab/settings.py +++ b/procollab/settings.py @@ -108,6 +108,7 @@ "channels", "taggit", "django_prometheus", + "cacheops", ] MIDDLEWARE = [ @@ -186,20 +187,30 @@ } } + REDIS_CONN_URL = "redis://127.0.0.1:6379" + CACHES = { "default": { - "BACKEND": "django_prometheus.cache.backends.filebased.FileBasedCache", - "LOCATION": "/var/tmp/django_cache", + "BACKEND": "django_redis.cache.RedisCache", + "LOCATION": REDIS_CONN_URL, + "OPTIONS": { + "CLIENT_CLASS": "django_redis.client.DefaultClient", + }, } } CHANNEL_LAYERS = {"default": {"BACKEND": "channels.layers.InMemoryChannelLayer"}} else: + REDIS_CONN_URL = "redis://redis:6379" + # fixme CACHES = { "default": { - "BACKEND": "django.core.cache.backends.redis.RedisCache", - "LOCATION": "redis://redis:6379", + "BACKEND": "django_redis.cache.RedisCache", + "LOCATION": REDIS_CONN_URL, + "OPTIONS": { + "CLIENT_CLASS": "django_redis.client.DefaultClient", + }, } } @@ -355,3 +366,9 @@ ) DATA_UPLOAD_MAX_NUMBER_FIELDS = None # for mailing + +CACHEOPS_REDIS = REDIS_CONN_URL + +CACHEOPS = { + "users.CustomUser": {"ops": "all", "timeout": 60 * 15}, +} diff --git a/projects/signals.py b/projects/signals.py index 5682c296..d816ee32 100644 --- a/projects/signals.py +++ b/projects/signals.py @@ -3,6 +3,7 @@ from chats.models import ProjectChat from projects.models import Collaborator, Project +from django.core.cache import cache @receiver(post_save, sender=Project) @@ -20,3 +21,7 @@ def create_project(sender, instance, created, **kwargs): Collaborator.objects.create( user=instance.leader, project=instance, role="Основатель" ) + + # invalidating cache from ProjectList view + keys = cache.keys("*project_list*") + cache.delete_many(keys) diff --git a/projects/views.py b/projects/views.py index ec784726..d5f8780a 100644 --- a/projects/views.py +++ b/projects/views.py @@ -10,6 +10,8 @@ from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response from rest_framework.views import APIView +from django.views.decorators.cache import cache_page +from django.utils.decorators import method_decorator from core.permissions import IsStaffOrReadOnly from core.serializers import SetLikedSerializer @@ -113,6 +115,10 @@ def post(self, request, *args, **kwargs): # set leader to current user return self.create(request, *args, **kwargs) + @method_decorator(cache_page(60 * 30, cache="default", key_prefix="project_list")) + def get(self, *args, **kwargs): + return super(ProjectList, self).get(*args, **kwargs) + class ProjectDetail(generics.RetrieveUpdateDestroyAPIView): queryset = Project.objects.get_projects_for_detail_view() diff --git a/pyproject.toml b/pyproject.toml index 7a00f2e7..8e0b3dd4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,6 +65,7 @@ django-stubs = {extras = ["compatible-mypy"], version = "^4.2.6"} djangorestframework-stubs = {extras = ["compatible-mypy"], version = "^3.14.4"} flake8-print = "^5.0.0" flake8-variables-names = "^0.0.6" +django-cacheops = "^7.0.2" [build-system] From 1e4d948856b6477039afeff11f99ba1036810148 Mon Sep 17 00:00:00 2001 From: Koshak Date: Sat, 9 Mar 2024 23:56:44 +0300 Subject: [PATCH 3/5] yml_fix --- .github/workflows/django-test.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/django-test.yml b/.github/workflows/django-test.yml index 4514720d..60827fd3 100644 --- a/.github/workflows/django-test.yml +++ b/.github/workflows/django-test.yml @@ -10,6 +10,19 @@ on: jobs: django-test: runs-on: ubuntu-latest + + services: + # Label used to access the service container + redis: + # Docker Hub image + image: redis + # Set health checks to wait until redis has started + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - uses: actions/checkout@v2 From 0b285bb5ddd76cc0217b824745d84513501f7507 Mon Sep 17 00:00:00 2001 From: Koshak Date: Sat, 9 Mar 2024 23:59:09 +0300 Subject: [PATCH 4/5] yml_fix --- .github/workflows/django-test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/django-test.yml b/.github/workflows/django-test.yml index 60827fd3..5c20a344 100644 --- a/.github/workflows/django-test.yml +++ b/.github/workflows/django-test.yml @@ -22,6 +22,9 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 + ports: + # Maps port 6379 on service container to the host + - 6379:6379 steps: - uses: actions/checkout@v2 From 45271b6b613bb9a40597dee0da8aa7de396a8f01 Mon Sep 17 00:00:00 2001 From: Koshak Date: Sun, 10 Mar 2024 00:01:40 +0300 Subject: [PATCH 5/5] deleted comments from yml --- .github/workflows/django-test.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/django-test.yml b/.github/workflows/django-test.yml index 5c20a344..c5f45215 100644 --- a/.github/workflows/django-test.yml +++ b/.github/workflows/django-test.yml @@ -12,18 +12,14 @@ jobs: runs-on: ubuntu-latest services: - # Label used to access the service container redis: - # Docker Hub image image: redis - # Set health checks to wait until redis has started options: >- --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5 ports: - # Maps port 6379 on service container to the host - 6379:6379 steps: