From 081d560bc40a5243240cd9577a4e920416cdc2d2 Mon Sep 17 00:00:00 2001 From: pictuga Date: Wed, 31 Oct 2018 21:47:19 +0100 Subject: [PATCH] feeds: create obj to keep FeedItems unique --- morss/feeds.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/morss/feeds.py b/morss/feeds.py index a2cd71f..c626889 100644 --- a/morss/feeds.py +++ b/morss/feeds.py @@ -303,6 +303,24 @@ class FeedList(object): def __len__(self): return len(self.getter()) +class Uniq(object): + _map = {} + _id = None + + def __new__(cls, *args, **kwargs): + # check if an item was already created for it + # if so, reuse it + # if not, create a new one + + tmp_id = cls._gen_id(*args, **kwargs) + if tmp_id is not None and tmp_id in cls._map: + return cls._map[tmp_id] + + else: + obj = object.__new__(cls, *args, **kwargs) + obj.__init__(*args, **kwargs) + cls._map[obj._id] = obj + return obj class FeedListDescriptor(object): """