add a few more configurations
This commit is contained in:
parent
36163b6136
commit
ead2056e9d
7 changed files with 73 additions and 45 deletions
|
@ -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")
|
||||
|
||||
|
|
|
@ -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,6 +165,7 @@ class DiscoverGenerator(BaseJob):
|
|||
tags = TagManager.popular_tags(days=14, local_only=local)[:40]
|
||||
excluding_identities = Takahe.get_no_discover_identities()
|
||||
|
||||
if settings.NEODB_DISCOVER_SHOW_POPULAR_POSTS:
|
||||
reviews = (
|
||||
Review.objects.filter(visibility=0)
|
||||
.exclude(owner_id__in=excluding_identities)
|
||||
|
@ -189,12 +190,14 @@ class DiscoverGenerator(BaseJob):
|
|||
).values_list("pk", flat=True)[:10]
|
||||
)
|
||||
| set(
|
||||
Takahe.get_popular_posts(1, 0, excluding_identities, local).values_list(
|
||||
"pk", flat=True
|
||||
)[:3]
|
||||
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)
|
||||
|
|
|
@ -87,9 +87,9 @@
|
|||
<li class="card">
|
||||
<a href="{{ item.url }}" title="{{ item.display_title }}">
|
||||
<img src="{{ item.cover|thumb:'normal' }}"
|
||||
alt="{{ item.display_title }}"
|
||||
alt="{{ item.title }}"
|
||||
loading="lazy">
|
||||
<div class="card-title">{{ item.display_title }}</div>
|
||||
<div class="card-title">{{ item.title }}</div>
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
|
|
@ -263,8 +263,13 @@ def discover(request):
|
|||
layout = request.user.preference.discover_layout
|
||||
identity = request.user.identity
|
||||
announcements = []
|
||||
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 = []
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue