Example #1
0
def refresh_thread_count_cache(sender, **kwargs):
    thread = kwargs["instance"]
    cache.delete("MailingList:%s:recent_threads" % thread.mailinglist_id)
    # don't warm up the cache in batch mode (mass import)
    if not getattr(settings, "HYPERKITTY_BATCH_MODE", False):
        # pylint: disable=pointless-statement
        thread.mailinglist.recent_threads
Example #2
0
 def test_overview_cleaned_cache(self):
     # Test the overview page with a clean cache (different code path for
     # MailingList.recent_threads)
     cache.delete("MailingList:[email protected]:recent_threads")
     response = self.client.get(reverse('hk_list_overview', args=["*****@*****.**"]))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.context["view_name"], "overview")
     self.assertEqual(len(response.context["top_threads"]), 1)
     self.assertEqual(len(response.context["most_active_threads"]), 1)
     self.assertEqual(len(response.context["pop_threads"]), 0)
Example #3
0
 def _recent_threads_cache_rebuild(self):
     begin_date, end_date = self.get_recent_dates()
     cache_key = "MailingList:%s:recent_threads" % self.name
     cache.delete(cache_key)
     cache.delete("%s_count" % cache_key)
     # don't warm up the cache in batch mode (mass import)
     if not getattr(settings, "HYPERKITTY_BATCH_MODE", False):
         thread_ids = list(self.get_threads_between(begin_date, end_date).values_list("id", flat=True))
         cache.set(cache_key, thread_ids, 3600 * 12)  # 12 hours
         cache.set("%s_count" % cache_key, len(thread_ids), 3600 * 12)
Example #4
0
def subscribe(list_address, user):
    client = get_mailman_client()
    rest_list = client.get_list(list_address)
    subscription_policy = rest_list.settings.get(
        "subscription_policy", "moderate")
    if subscription_policy in ("moderate", "confirm_then_moderate"):
        return # We don't want to bypass moderation, don't subscribe
    try:
        member = rest_list.get_member(user.email)
    except ValueError:
        # not subscribed yet, subscribe the user without email delivery
        member = rest_list.subscribe(user.email,
                "%s %s" % (user.first_name, user.last_name))
        member.preferences["delivery_status"] = "by_user"
        member.preferences.save()
        cache.delete("User:%s:subscriptions" % user.id)
Example #5
0
def subscribe(list_address, user):
    client = get_mailman_client()
    rest_list = client.get_list(list_address)
    subscription_policy = rest_list.settings.get("subscription_policy",
                                                 "moderate")
    # Add a flag to return that would tell the user they have been subscribed to
    # the current list.
    subscribed_now = False
    try:
        member = rest_list.get_member(user.email)
    except ValueError:
        # We don't want to bypass moderation, don't subscribe. Instead
        # raise an error so that it can be caught to show the user
        if subscription_policy in ("moderate", "confirm_then_moderate"):
            raise ModeratedListException(
                "This list is moderated, please subscribe"
                " to it before posting.")

        # not subscribed yet, subscribe the user without email delivery
        member = rest_list.subscribe(user.email,
                                     "%s %s" %
                                     (user.first_name, user.last_name),
                                     pre_verified=True,
                                     pre_confirmed=True)
        # The result can be a Member object or a dict if the subscription can't
        # be done directly, or if it's pending, or something else.
        # Broken API :-(
        if isinstance(member, dict):
            logger.info("Subscription for %s to %s is pending", user.email,
                        list_address)
            return subscribed_now
        member.preferences["delivery_status"] = "by_user"
        member.preferences.save()
        subscribed_now = True
        cache.delete("User:%s:subscriptions" % user.id)
        logger.info("Subscribing %s to %s on first post", user.email,
                    list_address)

    return subscribed_now
Example #6
0
def subscribe(list_address, user, email=None, display_name=None):
    if email is None:
        email = user.email
    if display_name is None:
        display_name = "%s %s" % (user.first_name, user.last_name)
    client = get_mailman_client()
    rest_list = client.get_list(list_address)
    subscription_policy = rest_list.settings.get(
        "subscription_policy", "moderate")
    # Add a flag to return that would tell the user they have been subscribed to
    # the current list.
    subscribed_now = False
    try:
        member = rest_list.get_member(email)
    except ValueError:
        # We don't want to bypass moderation, don't subscribe. Instead
        # raise an error so that it can be caught to show the user
        if subscription_policy in ("moderate", "confirm_then_moderate"):
            raise ModeratedListException("This list is moderated, please subscribe"
                                         " to it before posting.")

        # not subscribed yet, subscribe the user without email delivery
        member = rest_list.subscribe(email, display_name,
                pre_verified=True, pre_confirmed=True)
        # The result can be a Member object or a dict if the subscription can't
        # be done directly, or if it's pending, or something else.
        # Broken API :-(
        if isinstance(member, dict):
            logger.info("Subscription for %s to %s is pending",
                        email, list_address)
            return subscribed_now
        member.preferences["delivery_status"] = "by_user"
        member.preferences.save()
        subscribed_now = True
        cache.delete("User:%s:subscriptions" % user.id, version=2)
        logger.info("Subscribing %s to %s on first post",
                    email, list_address)

    return subscribed_now
Example #7
0
def Vote_clean_cache(sender, **kwargs):
    """Delete cached vote values for Email and Thread instance"""
    vote = kwargs["instance"]
    cache.delete("Thread:%s:votes" % vote.email.thread_id)
    # re-populate the cache?
    cache.delete("Email:%s:votes" % vote.email_id)
Example #8
0
def refresh_email_count_cache(sender, **kwargs):
    email = kwargs["instance"]
    cache.delete("Thread:%s:emails_count" % email.thread_id)
    cache.delete("Thread:%s:participants_count" % email.thread_id)
    cache.delete("MailingList:%s:recent_participants_count"
                 % email.mailinglist_id)
    cache.delete("MailingList:%s:top_posters" % email.mailinglist_id)
    cache.delete(make_template_fragment_key(
        "thread_participants", [email.thread_id]))
    cache.delete("MailingList:%s:p_count_for:%s:%s"
                 % (email.mailinglist_id, email.date.year, email.date.month))
    # don't warm up the cache in batch mode (mass import)
    if not getattr(settings, "HYPERKITTY_BATCH_MODE", False):
        # pylint: disable=pointless-statement
        try:
            email.thread.emails_count
            email.thread.participants_count
            email.mailinglist.recent_participants_count
            email.mailinglist.top_posters
            email.mailinglist.get_participants_count_for_month(
                email.date.year, email.date.month)
        except (Thread.DoesNotExist, MailingList.DoesNotExist):
            pass # it's post_delete, those may have been deleted too
Example #9
0
 def _clean_cache(self):
     """Delete cached vote values for Email and Thread instance"""
     cache.delete("Thread:%s:votes" % self.email.thread_id)
     # re-populate the cache?
     cache.delete("Email:%s:votes" % self.email_id)