diff --git a/dalec_discourse/__init__.py b/dalec_discourse/__init__.py index 3dc1f76..485f44a 100644 --- a/dalec_discourse/__init__.py +++ b/dalec_discourse/__init__.py @@ -1 +1 @@ -__version__ = "0.1.0" +__version__ = "0.1.1" diff --git a/dalec_discourse/proxy.py b/dalec_discourse/proxy.py index 707523b..217b163 100644 --- a/dalec_discourse/proxy.py +++ b/dalec_discourse/proxy.py @@ -6,6 +6,7 @@ from django.utils.timezone import now # DALEC imports +from dalec import settings as app_settings from dalec.proxy import Proxy from pydiscourse import DiscourseClient @@ -79,7 +80,11 @@ def _fetch_latest_topics(self, nb, channel=None, channel_object=None): contents = {} categories = {} username2name = {} - for topic in topics: + NB_KEPT = app_settings.get_for("NB_CONTENTS_KEPT", "discourse", "topic") + for i, topic in enumerate(topics): + if i > NB_KEPT: + # Early return + break # cache category to avoid multiple request category_id = topic["category_id"] if category_id not in categories.keys(): @@ -88,8 +93,8 @@ def _fetch_latest_topics(self, nb, channel=None, channel_object=None): else: category = categories[category_id] - post_url = "{}/t/{}/{}".format( - settings.DALEC_DISCOURSE_BASE_URL, topic["slug"], topic["id"] + post_url = "{}/t/{}/{}/{}".format( + settings.DALEC_DISCOURSE_BASE_URL, topic["slug"], topic["id"], topic["posts_count"] ) topic["id"] = str(topic["id"]) @@ -139,9 +144,9 @@ def _fetch_user_topics_and_replies(self, nb, channel=None, channel_object=None): """ if channel != "user": - raise ValueError(f"channel should be in : user .") + raise ValueError("channel should be in : user .") if not channel_object: - raise ValueError(f"channel_object must be defined") + raise ValueError("channel_object must be defined") # 4 = topic # 5 = reply diff --git a/tbump.toml b/tbump.toml index 2ffd994..45b6471 100644 --- a/tbump.toml +++ b/tbump.toml @@ -1,5 +1,5 @@ [version] -current = "0.1.0" +current = "0.1.1" # valid versions: # we use semver @@ -52,10 +52,6 @@ src = "dalec_discourse/__init__.py" # run after the files have been patched # and before the git commit is made -[[before_commit]] -name = "check black" -cmd = "black ./" - # Or run some commands after the git tag and the branch # have been pushed: # [[after_push]]