Improve the publication table / data types to denormalize the values
Returning profile values where necessary will remove the need to compute heavy joins unless the user actually wants all the data. Now Publication points at OrderProfiles which don't expose the sequences Orders->Sequence->EntryProfile avoids including the full `text` for the sequence.
This commit is contained in:
parent
63e51fa017
commit
86b0d88874
4 changed files with 82 additions and 11 deletions
|
|
@ -1,5 +1,14 @@
|
|||
from .data import Publication, PublicationProfile, Order, Sequence, Entry
|
||||
from .data import Publication, PublicationProfile, Order, Sequence, Entry, OrderProfile
|
||||
from .service import PublicationService
|
||||
from .repo import PublicationRepo
|
||||
|
||||
__all__ = ['Publication', 'PublicationProfile', 'Order', 'Sequence', 'Entry', 'PublicationService', 'PublicationRepo']
|
||||
__all__ = [
|
||||
'Publication',
|
||||
'PublicationProfile',
|
||||
'Order',
|
||||
'OrderProfile',
|
||||
'Sequence',
|
||||
'Entry',
|
||||
'PublicationService',
|
||||
'PublicationRepo',
|
||||
]
|
||||
|
|
|
|||
|
|
@ -2,25 +2,44 @@ from datetime import timedelta
|
|||
from dataclasses import dataclass, field
|
||||
|
||||
|
||||
@dataclass
|
||||
class EntryProfile:
|
||||
id: int
|
||||
title: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Entry:
|
||||
id: int
|
||||
title: str
|
||||
text: str
|
||||
|
||||
def to_profile(self) -> EntryProfile:
|
||||
return EntryProfile(self.id, self.title)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Sequence:
|
||||
position: int
|
||||
entry: Entry
|
||||
entry: EntryProfile
|
||||
duration: timedelta | None
|
||||
|
||||
|
||||
@dataclass
|
||||
class OrderProfile:
|
||||
id: int
|
||||
title: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Order:
|
||||
id: int
|
||||
title: str
|
||||
sequence_entries: list[Sequence]
|
||||
|
||||
def to_profile(self) -> OrderProfile:
|
||||
return OrderProfile(id=self.id, title=self.title)
|
||||
|
||||
|
||||
@dataclass
|
||||
class PublicationProfile:
|
||||
|
|
@ -35,7 +54,7 @@ class Publication:
|
|||
title: str
|
||||
description: str
|
||||
by_line: str
|
||||
orders: list[Order] = field(default_factory=list)
|
||||
orders: list[OrderProfile] = field(default_factory=list)
|
||||
|
||||
# Rather than using a subclass I think this makes sense
|
||||
def to_profile(self) -> PublicationProfile:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import abc
|
||||
|
||||
from .data import Publication, PublicationProfile
|
||||
from .data import Publication, PublicationProfile, Order, Entry
|
||||
|
||||
|
||||
class PublicationRepo(abc.ABC):
|
||||
|
|
@ -15,3 +15,11 @@ class PublicationRepo(abc.ABC):
|
|||
@abc.abstractmethod
|
||||
def get_all_publications(self) -> list[PublicationProfile]:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_full_order(self, order_id: int) -> Order | None:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def get_full_entry(self, entry_id: int) -> Entry | None:
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue