66
77from rss_glue .logger import logger
88from rss_glue .resources import global_config , utc_now
9+ from rss_glue .utils import from_dict
910
1011
1112@dataclass
@@ -54,7 +55,8 @@ def to_dict(self) -> dict:
5455@dataclass
5556class ReferenceFeedItem (FeedItem ):
5657 """
57- A ReferenceFeedItem is a reference to another feed item.
58+ A ReferenceFeedItem contains a reference to another feed item.
59+ It is only useful if your feed needs to store ADDITIONAL data to the post.
5860 """
5961
6062 subpost : FeedItem
@@ -72,6 +74,11 @@ def hashkey(self):
7274
7375 @staticmethod
7476 def load (obj : dict , source : "BaseFeed" ):
77+ """
78+ A reference feed has a load function which should take the contents of the
79+ raw JSON object kept in the cache and return a fully "hydrated" FeedItem
80+ which probably references other feed item(s).
81+ """
7582 obj ["subpost" ] = source .post (obj ["subpost" ])
7683 if not obj ["subpost" ]:
7784 logger .error (f"missing reference ns={ obj ['namespace' ]} subpost={ obj ['id' ]} " )
@@ -276,9 +283,7 @@ def post(self, post_id: str) -> Optional[FeedItem]:
276283 if not cached :
277284 return None
278285
279- # Load the cached post
280- loaded = self .post_cls .load (cached , self )
281- if not loaded :
282- return None
286+ cached ["subpost" ] = cached ["id" ]
287+ loaded = self .post_cls .load (cached , self .source )
283288
284- return self .post_cls ( ** loaded )
289+ return from_dict ( self .post_cls , loaded )
0 commit comments