Skip to content

Commit

Permalink
Merge pull request #3 from weber-s/main
Browse files Browse the repository at this point in the history
Early return + complete post url
  • Loading branch information
weber-s authored Sep 6, 2023
2 parents f4561f2 + 741057b commit 270ae5c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dalec_discourse/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.0"
__version__ = "0.1.1"
15 changes: 10 additions & 5 deletions dalec_discourse/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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():
Expand All @@ -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"])
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions tbump.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[version]
current = "0.1.0"
current = "0.1.1"

# valid versions:
# we use semver
Expand Down Expand Up @@ -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]]
Expand Down

0 comments on commit 270ae5c

Please sign in to comment.