Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/django-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ on:
jobs:
django-test:
runs-on: ubuntu-latest

services:
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379

steps:
- uses: actions/checkout@v2

Expand Down
26 changes: 26 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions procollab/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"channels",
"taggit",
"django_prometheus",
"cacheops",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -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",
},
}
Comment on lines +194 to 199
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если использовать FileBasedCache нельзя тянуть все ключи содержащие project_list, инвалидация становится невозможной.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

очень не хочется на локалке каждый раз поднимать редис чтобы кеш работал, с этим разве нельзя сделать ничего?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно накостылить свой client_class для FileBasedCache, который будет искать по совпадениям в ключах, но не вижу проблем запускать редис в локале, wsl позволяет это одной строчкой сделать

}

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",
},
}
}

Expand Down Expand Up @@ -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},
}
5 changes: 5 additions & 0 deletions projects/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -18,3 +19,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)
6 changes: 6 additions & 0 deletions projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ 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"
pandas = "^2.2.1"



[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
1 change: 1 addition & 0 deletions vacancy/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.contrib.contenttypes.models import ContentType
from rest_framework import serializers


from core.models import Skill, SkillToObject
from core.serializers import SkillToObjectSerializer
from projects.models import Project
Expand Down