perf: improved campaigns suggestion perfomance by caching some things

This commit is contained in:
ITQ
2025-02-21 13:31:39 +03:00
parent 9d92bbdc68
commit f8ae0798d3
9 changed files with 220 additions and 64 deletions
@@ -1,3 +1,6 @@
from typing import Any
from django.core.cache import cache
from django.db import models
from apps.advertiser.models import Advertiser
@@ -21,6 +24,15 @@ class Mlscore(BaseModel):
def __str__(self) -> str:
return f"{self.advertiser.name} | {self.client.login}"
def save(self, *args: Any, **kwargs: Any) -> None:
super().save(*args, **kwargs)
self.setup_cache()
def setup_cache(self) -> None:
cache.add(f"mlscore_{self.client_id}_{self.advertiser_id}", self.score)
cache.set(f"mlscore_{self.client_id}_{self.advertiser_id}", self.score)
class Meta:
unique_together = (
"advertiser",