Skip to content

Commit

Permalink
remove original related barrier
Browse files Browse the repository at this point in the history
  • Loading branch information
abarolo authored and abarolo committed Feb 25, 2024
1 parent 4864a45 commit 7ce3c59
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 412 deletions.

This file was deleted.

186 changes: 0 additions & 186 deletions api/barriers/related_barrier.py

This file was deleted.

32 changes: 21 additions & 11 deletions api/barriers/signals/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from django.db.models.signals import post_save, pre_save
from django.dispatch import receiver
from notifications_python_client.notifications import NotificationsAPIClient
from related_barriers import model
from related_barriers.model import BARRIER_UPDATE_FIELDS

from api.assessment.models import (
EconomicAssessment,
Expand All @@ -20,7 +22,6 @@
PublicBarrier,
PublicBarrierLightTouchReviews,
)
from api.barriers.related_barrier import RELEVANT_BARRIER_FIELDS, SimilarityScoreMatrix
from api.metadata.constants import TOP_PRIORITY_BARRIER_STATUS

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -378,16 +379,25 @@ def barrier_changed_after_published(sender, instance, **kwargs):


@receiver(pre_save, sender=Barrier)
def barrier_update_similarity_scores(sender, instance, *args, **kwargs):
def related_barrier_update_embeddings(sender, instance, *args, **kwargs):
try:
current_barrier_object = sender.objects.get(pk=instance.pk)
except sender.DoesNotExist:
pass # the barrier is new, we handle this elsewhere
else:
changed = any(
getattr(current_barrier_object, field) != getattr(instance, field)
for field in RELEVANT_BARRIER_FIELDS
)
if changed and not current_barrier_object.draft:
similarity_score_matrix = SimilarityScoreMatrix.retrieve_matrix()
similarity_score_matrix.update_matrix(instance)
logger.info(f"No Barrier found: {instance.pk}")
return

changed = any(
getattr(current_barrier_object, field) != getattr(instance, field)
for field in BARRIER_UPDATE_FIELDS
)
if changed and not current_barrier_object.draft:
try:
model.db.update_barrier(
{
"id": str(current_barrier_object.id),
"barrier_corpus": model.barrier_to_corpus(current_barrier_object),
}
)
except Exception as e:
# We don't want barrier embedding updates to break worker so just log error
logger.critical(str(e))

This file was deleted.

1 change: 1 addition & 0 deletions api/related_barriers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def load_transformer():

SIMILARITY_THRESHOLD = 0.19
SIMILAR_BARRIERS_LIMIT = 5
BARRIER_UPDATE_FIELDS = ["title", "summary"]


EMBEDDINGS_CACHE_KEY = "EMBEDDINGS_CACHE_KEY"
Expand Down
Loading

0 comments on commit 7ce3c59

Please sign in to comment.