Skip to content

Commit

Permalink
remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderGi committed Sep 20, 2023
1 parent f594d02 commit 1547646
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
5 changes: 3 additions & 2 deletions daras_ai_v2/glossary.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import gooey_ui as st
from daras_ai_v2.redis_cache import redis_cache_decorator
from contextlib import contextmanager
from glossary_resources.models import GlossaryResources, AsyncAtomic
from glossary_resources.models import GlossaryResources
from django.db import transaction

DEFAULT_GLOSSARY_URL = "https://docs.google.com/spreadsheets/d/1IRHKcOC86oZXwMB0hR7eej7YVg5kUHpriZymwYQcQX4/edit?usp=sharing" # only viewing access
PROJECT_ID = "dara-c1b52" # GCP project id
Expand Down Expand Up @@ -43,7 +44,7 @@ def glossary_resource(f_url: str = DEFAULT_GLOSSARY_URL):
return

# I could not get this to work with concurrent translate requests without locking everything :(
with AsyncAtomic():
with transaction.atomic():
resource, created = GlossaryResources.objects.select_for_update().get_or_create(
f_url=f_url
)
Expand Down
14 changes: 1 addition & 13 deletions glossary_resources/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import models, transaction
from django.db import models
from bots.custom_fields import CustomURLField
import uuid
from asgiref.sync import sync_to_async
Expand All @@ -15,15 +15,3 @@ class Meta:

def get_clean_name(self):
return str(self.glossary_name).lower()


class AsyncAtomic(transaction.Atomic):
def __init__(self, using=None, savepoint=True, durable=False):
super().__init__(using, savepoint, durable)

async def __aenter__(self):
await sync_to_async(super().__enter__)()
return self

async def __aexit__(self, exc_type, exc_value, traceback):
await sync_to_async(super().__exit__)(exc_type, exc_value, traceback)

0 comments on commit 1547646

Please sign in to comment.