removed redundant query functions
This commit is contained in:
parent
a136c3d362
commit
37f3ec31cc
|
@ -8,13 +8,10 @@ from tortoise.transactions import atomic
|
||||||
from mobilizon_reshare.dataclasses import MobilizonEvent, EventPublication
|
from mobilizon_reshare.dataclasses import MobilizonEvent, EventPublication
|
||||||
from mobilizon_reshare.models.event import Event
|
from mobilizon_reshare.models.event import Event
|
||||||
from mobilizon_reshare.models.publication import Publication
|
from mobilizon_reshare.models.publication import Publication
|
||||||
from mobilizon_reshare.models.publisher import Publisher
|
|
||||||
from mobilizon_reshare.storage.query.exceptions import EventNotFound
|
|
||||||
from mobilizon_reshare.storage.query.read import (
|
from mobilizon_reshare.storage.query.read import (
|
||||||
prefetch_event_relations,
|
prefetch_event_relations,
|
||||||
_add_date_window,
|
_add_date_window,
|
||||||
prefetch_publication_relations,
|
prefetch_publication_relations,
|
||||||
get_event,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,15 +36,3 @@ async def get_publication(publication_id: UUID):
|
||||||
)
|
)
|
||||||
except DoesNotExist:
|
except DoesNotExist:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
async def get_publisher_by_name(name) -> Publisher:
|
|
||||||
return await Publisher.filter(name=name).first()
|
|
||||||
|
|
||||||
|
|
||||||
async def is_known(event: MobilizonEvent) -> bool:
|
|
||||||
try:
|
|
||||||
await get_event(event.mobilizon_id)
|
|
||||||
return True
|
|
||||||
except EventNotFound:
|
|
||||||
return False
|
|
||||||
|
|
|
@ -5,11 +5,7 @@ import arrow
|
||||||
from tortoise.transactions import atomic
|
from tortoise.transactions import atomic
|
||||||
|
|
||||||
from mobilizon_reshare.dataclasses import MobilizonEvent
|
from mobilizon_reshare.dataclasses import MobilizonEvent
|
||||||
from mobilizon_reshare.dataclasses.to_split import (
|
from mobilizon_reshare.dataclasses.to_split import events_without_publications
|
||||||
events_without_publications,
|
|
||||||
get_publisher_by_name,
|
|
||||||
is_known,
|
|
||||||
)
|
|
||||||
from mobilizon_reshare.models.event import Event
|
from mobilizon_reshare.models.event import Event
|
||||||
from mobilizon_reshare.models.publication import Publication
|
from mobilizon_reshare.models.publication import Publication
|
||||||
from mobilizon_reshare.models.publisher import Publisher
|
from mobilizon_reshare.models.publisher import Publisher
|
||||||
|
@ -26,8 +22,8 @@ async def create_publisher(name: str, account_ref: Optional[str] = None) -> None
|
||||||
@atomic()
|
@atomic()
|
||||||
async def upsert_publication(publication_report, event):
|
async def upsert_publication(publication_report, event):
|
||||||
|
|
||||||
publisher = await get_publisher_by_name(
|
publisher_model = await (
|
||||||
name=publication_report.publication.publisher.name
|
Publisher.get(name=publication_report.publication.publisher.name).first()
|
||||||
)
|
)
|
||||||
old_publication = await Publication.filter(
|
old_publication = await Publication.filter(
|
||||||
id=publication_report.publication.id
|
id=publication_report.publication.id
|
||||||
|
@ -44,7 +40,7 @@ async def upsert_publication(publication_report, event):
|
||||||
await Publication.create(
|
await Publication.create(
|
||||||
id=publication_report.publication.id,
|
id=publication_report.publication.id,
|
||||||
event_id=event.id,
|
event_id=event.id,
|
||||||
publisher_id=publisher.id,
|
publisher_id=publisher_model.id,
|
||||||
status=publication_report.status,
|
status=publication_report.status,
|
||||||
reason=publication_report.reason,
|
reason=publication_report.reason,
|
||||||
timestamp=arrow.now().datetime,
|
timestamp=arrow.now().datetime,
|
||||||
|
@ -76,7 +72,7 @@ async def create_unpublished_events(
|
||||||
"""
|
"""
|
||||||
# There are three cases:
|
# There are three cases:
|
||||||
for event in events_from_mobilizon:
|
for event in events_from_mobilizon:
|
||||||
if not await is_known(event):
|
if not await Event.exists(mobilizon_id=event.mobilizon_id):
|
||||||
# Either an event is unknown
|
# Either an event is unknown
|
||||||
await event.to_model().save()
|
await event.to_model().save()
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue