Skip to content

Commit

Permalink
app: use joined eager loading for objects in source.collection
Browse files Browse the repository at this point in the history
Suggested by @rmol in private conversation to replace the
expire_all
  • Loading branch information
redshiftzero committed Mar 16, 2020
1 parent eb76a2b commit 11f55ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions securedrop_client/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ class Message(Base):
source_id = Column(Integer, ForeignKey('sources.id'), nullable=False)
source = relationship("Source",
backref=backref("messages", order_by=id,
cascade="delete"))
cascade="delete"),
lazy="joined")

def __init__(self, **kwargs: Any) -> None:
if 'file_counter' in kwargs:
Expand Down Expand Up @@ -174,7 +175,8 @@ class File(Base):
source_id = Column(Integer, ForeignKey('sources.id'), nullable=False)
source = relationship("Source",
backref=backref("files", order_by=id,
cascade="delete"))
cascade="delete"),
lazy="joined")

def __init__(self, **kwargs: Any) -> None:
if 'file_counter' in kwargs:
Expand Down Expand Up @@ -221,7 +223,8 @@ class Reply(Base):
source_id = Column(Integer, ForeignKey('sources.id'), nullable=False)
source = relationship("Source",
backref=backref("replies", order_by=id,
cascade="delete"))
cascade="delete"),
lazy="joined")

journalist_id = Column(Integer, ForeignKey('users.id'))
journalist = relationship(
Expand Down Expand Up @@ -291,7 +294,8 @@ class DraftReply(Base):
source_id = Column(Integer, ForeignKey('sources.id'), nullable=False)
source = relationship("Source",
backref=backref("draftreplies", order_by=id,
cascade="delete"))
cascade="delete"),
lazy="joined")
journalist_id = Column(Integer, ForeignKey('users.id'))
journalist = relationship(
"User", backref=backref('draftreplies', order_by=id))
Expand Down
2 changes: 1 addition & 1 deletion securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ def on_source_changed(self):
if not source:
return

self.controller.session.expire_all()
self.controller.session.refresh(source)
# Try to get the SourceConversationWrapper from the persistent dict,
# else we create it.
try:
Expand Down

0 comments on commit 11f55ae

Please sign in to comment.