diff --git a/boofilsic/settings.py b/boofilsic/settings.py index 0ffb5411..d80add93 100644 --- a/boofilsic/settings.py +++ b/boofilsic/settings.py @@ -84,9 +84,13 @@ env = environ.FileAwareEnv( # Number of marks required for an item to be included in discover NEODB_MIN_MARKS_FOR_DISCOVER=(int, 1), # if True, only show title language with NEODB_PREFERRED_LANGUAGES - NEODB_FILTER_LANGUAGE_FOR_DISCOVER=(bool, False), + NEODB_DISCOVER_FILTER_LANGUAGE=(bool, False), # if True, only show items marked by local users rather than entire network - NEODB_FILTER_LOCAL_ONLY_FOR_DISCOVER=(bool, False), + NEODB_DISCOVER_SHOW_LOCAL_ONLY=(bool, False), + # if True, show popular public posts instead of recent ones. + NEODB_DISCOVER_SHOW_POPULAR_POSTS=(bool, False), + # update popular items every X minutes. + NEODB_DISCOVER_UPDATE_INTERVAL=(int, 60), # Disable cron jobs, * for all NEODB_DISABLE_CRON_JOBS=(list, []), # federated search peers @@ -219,8 +223,10 @@ DISABLE_DEFAULT_RELAY = env("NEODB_DISABLE_DEFAULT_RELAY", default=DEBUG) MIN_MARKS_FOR_DISCOVER = env("NEODB_MIN_MARKS_FOR_DISCOVER") -FILTER_LANGUAGE_FOR_DISCOVER = env("NEODB_FILTER_LANGUAGE_FOR_DISCOVER") -FILTER_LOCAL_ONLY_FOR_DISCOVER = env("NEODB_FILTER_LOCAL_ONLY_FOR_DISCOVER") +DISCOVER_UPDATE_INTERVAL = env("NEODB_DISCOVER_UPDATE_INTERVAL") +DISCOVER_FILTER_LANGUAGE = env("NEODB_DISCOVER_FILTER_LANGUAGE") +DISCOVER_SHOW_LOCAL_ONLY = env("NEODB_DISCOVER_SHOW_LOCAL_ONLY") +DISCOVER_SHOW_POPULAR_POSTS = env("NEODB_DISCOVER_SHOW_POPULAR_POSTS") MASTODON_ALLOWED_SITES = env("NEODB_LOGIN_MASTODON_WHITELIST") diff --git a/catalog/jobs/discover.py b/catalog/jobs/discover.py index 8fc479b8..49e8b18a 100644 --- a/catalog/jobs/discover.py +++ b/catalog/jobs/discover.py @@ -31,7 +31,7 @@ DAYS_FOR_TRENDS = 3 @JobManager.register class DiscoverGenerator(BaseJob): - interval = timedelta(hours=1) + interval = timedelta(minutes=settings.DISCOVER_UPDATE_INTERVAL) def get_popular_marked_item_ids(self, category, days, exisiting_ids): qs = ( @@ -39,9 +39,9 @@ class DiscoverGenerator(BaseJob): .filter(created_time__gt=timezone.now() - timedelta(days=days)) .exclude(item_id__in=exisiting_ids) ) - if settings.FILTER_LOCAL_ONLY_FOR_DISCOVER: + if settings.DISCOVER_SHOW_LOCAL_ONLY: qs = qs.filter(local=True) - if settings.FILTER_LANGUAGE_FOR_DISCOVER: + if settings.DISCOVER_FILTER_LANGUAGE: q = None for loc in PREFERRED_LOCALES: if q: @@ -63,7 +63,7 @@ class DiscoverGenerator(BaseJob): qs = Comment.objects.filter(q_item_in_category(ItemCategory.Podcast)).filter( created_time__gt=timezone.now() - timedelta(days=days) ) - if settings.FILTER_LOCAL_ONLY_FOR_DISCOVER: + if settings.DISCOVER_SHOW_LOCAL_ONLY: qs = qs.filter(local=True) return list( qs.annotate(p=F("item__podcastepisode__program")) @@ -87,7 +87,7 @@ class DiscoverGenerator(BaseJob): def run(self): logger.info("Discover data update start.") - local = settings.FILTER_LOCAL_ONLY_FOR_DISCOVER + local = settings.DISCOVER_SHOW_LOCAL_ONLY gallery_categories = [ ItemCategory.Book, ItemCategory.Movie, @@ -165,36 +165,39 @@ class DiscoverGenerator(BaseJob): tags = TagManager.popular_tags(days=14, local_only=local)[:40] excluding_identities = Takahe.get_no_discover_identities() - reviews = ( - Review.objects.filter(visibility=0) - .exclude(owner_id__in=excluding_identities) - .order_by("-created_time") - ) - if local: - reviews = reviews.filter(local=True) - post_ids = ( - set( - Takahe.get_popular_posts( - 28, settings.MIN_MARKS_FOR_DISCOVER, excluding_identities, local - ).values_list("pk", flat=True)[:5] + if settings.NEODB_DISCOVER_SHOW_POPULAR_POSTS: + reviews = ( + Review.objects.filter(visibility=0) + .exclude(owner_id__in=excluding_identities) + .order_by("-created_time") ) - | set( - Takahe.get_popular_posts( - 14, settings.MIN_MARKS_FOR_DISCOVER, excluding_identities, local - ).values_list("pk", flat=True)[:5] + if local: + reviews = reviews.filter(local=True) + post_ids = ( + set( + Takahe.get_popular_posts( + 28, settings.MIN_MARKS_FOR_DISCOVER, excluding_identities, local + ).values_list("pk", flat=True)[:5] + ) + | set( + Takahe.get_popular_posts( + 14, settings.MIN_MARKS_FOR_DISCOVER, excluding_identities, local + ).values_list("pk", flat=True)[:5] + ) + | set( + Takahe.get_popular_posts( + 7, settings.MIN_MARKS_FOR_DISCOVER, excluding_identities, local + ).values_list("pk", flat=True)[:10] + ) + | set( + Takahe.get_popular_posts( + 1, 0, excluding_identities, local + ).values_list("pk", flat=True)[:3] + ) + | set(reviews.values_list("posts", flat=True)[:5]) ) - | set( - Takahe.get_popular_posts( - 7, settings.MIN_MARKS_FOR_DISCOVER, excluding_identities, local - ).values_list("pk", flat=True)[:10] - ) - | set( - Takahe.get_popular_posts(1, 0, excluding_identities, local).values_list( - "pk", flat=True - )[:3] - ) - | set(reviews.values_list("posts", flat=True)[:5]) - ) + else: + post_ids = [] cache.set("public_gallery", gallery_list, timeout=None) cache.set("trends_links", trends, timeout=None) cache.set("featured_collections", collection_ids, timeout=None) diff --git a/catalog/templates/discover.html b/catalog/templates/discover.html index c5bcb7cf..ba52d67a 100644 --- a/catalog/templates/discover.html +++ b/catalog/templates/discover.html @@ -87,9 +87,9 @@
  • {{ item.display_title }} -
    {{ item.display_title }}
    +
    {{ item.title }}
  • {% endfor %} diff --git a/catalog/views.py b/catalog/views.py index 5b1e9c36..61969edd 100644 --- a/catalog/views.py +++ b/catalog/views.py @@ -263,8 +263,13 @@ def discover(request): layout = request.user.preference.discover_layout identity = request.user.identity announcements = [] - post_ids = cache.get("popular_posts", []) - popular_posts = Takahe.get_posts(post_ids).order_by("-published") + if settings.DISCOVER_SHOW_POPULAR_POSTS: + post_ids = cache.get("popular_posts", []) + popular_posts = Takahe.get_posts(post_ids).order_by("-published") + else: + popular_posts = Takahe.get_public_posts(settings.DISCOVER_SHOW_LOCAL_ONLY)[ + :20 + ] else: identity = None layout = [] diff --git a/compose.yml b/compose.yml index f1a083c1..f97ab9ff 100644 --- a/compose.yml +++ b/compose.yml @@ -34,8 +34,10 @@ x-shared: NEODB_DISABLE_CRON_JOBS: NEODB_SEARCH_PEERS: NEODB_MIN_MARKS_FOR_DISCOVER: - NEODB_FILTER_LANGUAGE_FOR_DISCOVER: - NEODB_FILTER_LOCAL_ONLY_FOR_DISCOVER: + NEODB_DISCOVER_UPDATE_INTERVAL: + NEODB_DISCOVER_FILTER_LANGUAGE: + NEODB_DISCOVER_SHOW_LOCAL_ONLY: + NEODB_DISCOVER_SHOW_POPULAR_POSTS: NEODB_SENTRY_DSN: TAKAHE_SENTRY_DSN: NEODB_SENTRY_SAMPLE_RATE: diff --git a/docs/configuration.md b/docs/configuration.md index b708b7db..f1581899 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -25,8 +25,9 @@ if you are doing debug or development: - `NEODB_SITE_HEAD` - `NEODB_SITE_DESCRIPTION` - `NEODB_PREFERRED_LANGUAGES` - preferred languages when importing titles from 3rd party sites like TMDB and Steam, comma-separated list of ISO-639-1 two-letter codes, `en,zh` by default. It can includes languages with no UI translations yet, e.g. if set to `ja,en,zh`, NeoDB scraper will fetch catalog metadata in three languages if they are available from third party sites, Japanese users (= whose browser language set to ja-JP) will see English UI with Japanese metadata. - - `NEODB_FILTER_LANGUAGE_FOR_DISCOVER` - `False` by default; when set to `True`, `/discover/` will only show items with languages match one of `NEODB_PREFERRED_LANGUAGES`. - - `NEODB_FILTER_LOCAL_ONLY_FOR_DISCOVER` - `False` by default; when set to `True`, only show items marked by local users rather than entire network in `/discover/` + - `NEODB_DISCOVER_FILTER_LANGUAGE` - `False` by default; when set to `True`, `/discover/` will only show items with languages match one of `NEODB_PREFERRED_LANGUAGES`. + - `NEODB_DISCOVER_SHOW_LOCAL_ONLY` - `False` by default; when set to `True`, only show items marked by local users rather than entire network on `/discover/` + - `NEODB_DISCOVER_UPDATE_INTERVAL` - minutes between each update for popular items on `/discover/` - `NEODB_SITE_LINKS` - a list of title and links to show in the footer, comma separated, e.g. `Feedback=https://discord.gg/8KweCuApaK,ToS=/pages/rules/` - `NEODB_INVITE_ONLY` - `False` by default, set to `True` to require invite code(generated by `neodb-manage invite --create`) to register - `NEODB_ENABLE_LOCAL_ONLY` - `False` by default, set to `True` to allow user to post marks as "local public" diff --git a/takahe/utils.py b/takahe/utils.py index 5bbc5569..e27afd50 100644 --- a/takahe/utils.py +++ b/takahe/utils.py @@ -837,6 +837,17 @@ class Takahe: Identity.objects.filter(discoverable=False).values_list("pk", flat=True) ) + @staticmethod + def get_public_posts(local_only=False): + qs = ( + Post.objects.exclude(state__in=["deleted", "deleted_fanned_out"]) + .filter(visibility__in=[0, 4]) + .order_by("-published") + ) + if local_only: + qs = qs.filter(local=True) + return qs + @staticmethod def get_popular_posts( days: int = 30,