Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev' into dev-server
Browse files Browse the repository at this point in the history
  • Loading branch information
shaheenhyderk committed Sep 25, 2024
2 parents 66055d0 + 174154c commit 6742c46
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
7 changes: 5 additions & 2 deletions api/dashboard/user/dash_user_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from utils.types import RoleType, WebHookActions, WebHookCategory
from utils.utils import CommonUtils, DateTimeUtils, DiscordWebhooks, send_template_mail
from . import dash_user_serializer
from django.core.cache import cache

BE_DOMAIN_NAME = decouple_config("BE_DOMAIN_NAME")

Expand All @@ -22,8 +23,10 @@ class UserInfoAPI(APIView):

def get(self, request):
user_muid = JWTUtils.fetch_muid(request)
user = User.objects.filter(muid=user_muid).first()

user = cache.get(f"db_user_{user_muid}")
if not user:
user = User.objects.filter(muid=user_muid).first()
cache.set(f"db_user_{user_muid}", user, timeout=10)
if user is None:
return CustomResponse(
general_message="No user data available"
Expand Down
16 changes: 14 additions & 2 deletions api/register/register_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
from rest_framework.views import APIView

from db.organization import Country, Department, District, Organization, State, Zone
from django.utils.decorators import method_decorator
from db.task import InterestGroup
from db.user import Role, User
from utils.response import CustomResponse
from utils.types import OrganizationType
from utils.utils import send_template_mail
from . import serializers
from .register_helper import get_auth_token
from django.views.decorators.cache import cache_page
from django.core.cache import cache


class UserRegisterValidateAPI(APIView):
Expand All @@ -24,12 +27,14 @@ def put(self, request):


class RoleAPI(APIView):
@method_decorator(cache_page(60 * 10))
def get(self, request):
roles = Role.objects.all().values("id", "title")
return CustomResponse(response={"roles": roles}).get_success_response()


class CollegesAPI(APIView):
@method_decorator(cache_page(60 * 10))
def get(self, request):
colleges = Organization.objects.filter(
org_type=OrganizationType.COLLEGE.value
Expand All @@ -39,6 +44,7 @@ def get(self, request):


class DepartmentAPI(APIView):
@method_decorator(cache_page(60 * 10))
def get(self, request):
department_serializer = Department.objects.all().values("id", "title")

Expand All @@ -52,6 +58,7 @@ def get(self, request):


class CompanyAPI(APIView):
@method_decorator(cache_page(60 * 10))
def get(self, request):
company_queryset = Organization.objects.filter(
org_type=OrganizationType.COMPANY.value
Expand All @@ -76,7 +83,7 @@ def post(self, request):
return CustomResponse(general_message="Invalid muid").get_failure_response()

serializer = serializers.LearningCircleUserSerializer(user)
id, muid, full_name, email, phone = serializer.data.values()
id, muid, full_name, email, phone = serializer.data.values()

name = full_name

Expand All @@ -103,8 +110,9 @@ def post(self, request):

if not create_user.is_valid():
return CustomResponse(message=create_user.errors).get_failure_response()

user = create_user.save()
cache.set(f"db_user_{user.muid}", user, timeout=20)
password = request.data["user"]["password"]

res_data = get_auth_token(user.muid, password)
Expand All @@ -123,6 +131,7 @@ def post(self, request):


class CountryAPI(APIView):
@method_decorator(cache_page(60 * 10))
def get(self, request):
countries = Country.objects.all()

Expand Down Expand Up @@ -203,6 +212,7 @@ def post(self, request):


class CommunityAPI(APIView):
@method_decorator(cache_page(60 * 10))
def get(self, request):
community_queryset = Organization.objects.filter(
org_type=OrganizationType.COMMUNITY.value
Expand All @@ -218,6 +228,7 @@ def get(self, request):


class AreaOfInterestAPI(APIView):
@method_decorator(cache_page(60 * 10))
def get(self, request):
aoi_queryset = InterestGroup.objects.all()

Expand Down Expand Up @@ -245,6 +256,7 @@ def post(self, request):


class UserCountryAPI(APIView):
@method_decorator(cache_page(60 * 10))
def get(self, request):
country = Country.objects.all()

Expand Down
23 changes: 21 additions & 2 deletions mulearnbackend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
https://docs.djangoproject.com/en/4.1/ref/settings/
"""


import os
from pathlib import Path

Expand Down Expand Up @@ -94,11 +93,14 @@

WSGI_APPLICATION = "mulearnbackend.wsgi.application"

REDIS_HOST = decouple_config("REDIS_HOST")
REDIS_PORT = decouple_config("REDIS_PORT")

CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [(decouple_config("REDIS_HOST"), decouple_config("REDIS_PORT"))],
"hosts": [(REDIS_HOST, REDIS_PORT)],
},
},
}
Expand All @@ -117,6 +119,23 @@
}
}

CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.db.DatabaseCache",
"LOCATION": "my_cache_table",
},
"redis": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": f"redis://{REDIS_HOST}:{REDIS_PORT}/1",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
},
}

# Use the Redis cache as the default cache
CACHES["default"] = CACHES["redis"]

# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators

Expand Down

0 comments on commit 6742c46

Please sign in to comment.