<commit_before>from django.conf import settings
from django.db import connection

from ..tasks import raven


@raven
def update_feed(feed_url, use_etags=True):
    from .models import UniqueFeed
    UniqueFeed.objects.update_feed(feed_url, use_etags)
    close_connection()


@raven
def read_later(entry_pk):
    from .models import Entry  # circular imports
    Entry.objects.get(pk=entry_pk).read_later()
    close_connection()


@raven
def update_unique_feed(feed_url):
    from .models import UniqueFeed, Feed
    feed, created = UniqueFeed.objects.get_or_create(
        url=feed_url,
        defaults={'subscribers': 1},
    )
    if not created:
        feed.subscribers = Feed.objects.filter(url=feed_url).count()
        feed.save()


def close_connection():
    """Close the connection only if not in eager mode"""
    if hasattr(settings, 'RQ'):
        if not settings.RQ.get('eager', True):
            connection.close()<commit_msg>Update favicon on UniqueFeed update<commit_after>from django.conf import settings
from django.db import connection

from ..tasks import raven


@raven
def update_feed(feed_url, use_etags=True):
    from .models import UniqueFeed
    UniqueFeed.objects.update_feed(feed_url, use_etags)
    close_connection()


@raven
def read_later(entry_pk):
    from .models import Entry  # circular imports
    Entry.objects.get(pk=entry_pk).read_later()
    close_connection()


@raven
def update_unique_feed(feed_url):
    from .models import UniqueFeed, Feed, Favicon
    feed, created = UniqueFeed.objects.get_or_create(
        url=feed_url,
        defaults={'subscribers': 1},
    )
    if not created:
        feed.subscribers = Feed.objects.filter(url=feed_url).count()
        feed.save()
    Favicon.objects.update_favicon(feed.link)


def close_connection():
    """Close the connection only if not in eager mode"""
    if hasattr(settings, 'RQ'):
        if not settings.RQ.get('eager', True):
            connection.close()
{'fraction_non_alphanumeric': 0.10259014728288471, 'fraction_numerical': 0.001015744032503809, 'mean_word_length': 3.5813953488372094, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6234883', 'n_tokens_mistral': 632, 'n_tokens_neox': 601, 'n_words': 151}