core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
node subscriptions can now be cached, this can be useful for components which must keep track of subscibers. rel 364
This commit is contained in:
parent
f90d76aa18
commit
317e8a6a94
1 changed files with 76 additions and 7 deletions
|
|
@ -60,6 +60,11 @@ class SyncState(enum.Enum):
|
|||
NO_SYNC = 4
|
||||
|
||||
|
||||
class SubscriptionState(enum.Enum):
|
||||
SUBSCRIBED = 1
|
||||
PENDING = 2
|
||||
|
||||
|
||||
class LegacyPickle(TypeDecorator):
|
||||
"""Handle troubles with data pickled by former version of SàT
|
||||
|
||||
|
|
@ -510,11 +515,37 @@ class PubsubNode(Base):
|
|||
extra = Column(JSON)
|
||||
|
||||
items = relationship("PubsubItem", back_populates="node", passive_deletes=True)
|
||||
subscriptions = relationship("PubsubSub", back_populates="node", passive_deletes=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"Pubsub node {self.name!r} at {self.service}"
|
||||
|
||||
|
||||
class PubsubSub(Base):
|
||||
"""Subscriptions to pubsub nodes
|
||||
|
||||
Used by components managing a pubsub service
|
||||
"""
|
||||
__tablename__ = "pubsub_subs"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("node_id", "subscriber"),
|
||||
)
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
node_id = Column(ForeignKey("pubsub_nodes.id", ondelete="CASCADE"), nullable=False)
|
||||
subscriber = Column(JID)
|
||||
state = Column(
|
||||
Enum(
|
||||
SubscriptionState,
|
||||
name="state",
|
||||
create_constraint=True,
|
||||
),
|
||||
nullable=True
|
||||
)
|
||||
|
||||
node = relationship("PubsubNode", back_populates="subscriptions")
|
||||
|
||||
|
||||
class PubsubItem(Base):
|
||||
__tablename__ = "pubsub_items"
|
||||
__table_args__ = (
|
||||
|
|
|
|||
Loading…
Reference in a new issue