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
|
# Number of marks required for an item to be included in discover
|
||||||
NEODB_MIN_MARKS_FOR_DISCOVER=(int, 1),
|
NEODB_MIN_MARKS_FOR_DISCOVER=(int, 1),
|
||||||
# if True, only show title language with NEODB_PREFERRED_LANGUAGES
|
# 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
|
# 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
|
# Disable cron jobs, * for all
|
||||||
NEODB_DISABLE_CRON_JOBS=(list, []),
|
NEODB_DISABLE_CRON_JOBS=(list, []),
|
||||||
# federated search peers
|
# 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")
|
MIN_MARKS_FOR_DISCOVER = env("NEODB_MIN_MARKS_FOR_DISCOVER")
|
||||||
|
|
||||||
FILTER_LANGUAGE_FOR_DISCOVER = env("NEODB_FILTER_LANGUAGE_FOR_DISCOVER")
|
DISCOVER_UPDATE_INTERVAL = env("NEODB_DISCOVER_UPDATE_INTERVAL")
|
||||||
FILTER_LOCAL_ONLY_FOR_DISCOVER = env("NEODB_FILTER_LOCAL_ONLY_FOR_DISCOVER")
|
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")
|
MASTODON_ALLOWED_SITES = env("NEODB_LOGIN_MASTODON_WHITELIST")
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ DAYS_FOR_TRENDS = 3
|
||||||
|
|
||||||
@JobManager.register
|
@JobManager.register
|
||||||
class DiscoverGenerator(BaseJob):
|
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):
|
def get_popular_marked_item_ids(self, category, days, exisiting_ids):
|
||||||
qs = (
|
qs = (
|
||||||
|
@ -39,9 +39,9 @@ class DiscoverGenerator(BaseJob):
|
||||||
.filter(created_time__gt=timezone.now() - timedelta(days=days))
|
.filter(created_time__gt=timezone.now() - timedelta(days=days))
|
||||||
.exclude(item_id__in=exisiting_ids)
|
.exclude(item_id__in=exisiting_ids)
|
||||||
)
|
)
|
||||||
if settings.FILTER_LOCAL_ONLY_FOR_DISCOVER:
|
if settings.DISCOVER_SHOW_LOCAL_ONLY:
|
||||||
qs = qs.filter(local=True)
|
qs = qs.filter(local=True)
|
||||||
if settings.FILTER_LANGUAGE_FOR_DISCOVER:
|
if settings.DISCOVER_FILTER_LANGUAGE:
|
||||||
q = None
|
q = None
|
||||||
for loc in PREFERRED_LOCALES:
|
for loc in PREFERRED_LOCALES:
|
||||||
if q:
|
if q:
|
||||||
|
@ -63,7 +63,7 @@ class DiscoverGenerator(BaseJob):
|
||||||
qs = Comment.objects.filter(q_item_in_category(ItemCategory.Podcast)).filter(
|
qs = Comment.objects.filter(q_item_in_category(ItemCategory.Podcast)).filter(
|
||||||
created_time__gt=timezone.now() - timedelta(days=days)
|
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)
|
qs = qs.filter(local=True)
|
||||||
return list(
|
return list(
|
||||||
qs.annotate(p=F("item__podcastepisode__program"))
|
qs.annotate(p=F("item__podcastepisode__program"))
|
||||||
|
@ -87,7 +87,7 @@ class DiscoverGenerator(BaseJob):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
logger.info("Discover data update start.")
|
logger.info("Discover data update start.")
|
||||||
local = settings.FILTER_LOCAL_ONLY_FOR_DISCOVER
|
local = settings.DISCOVER_SHOW_LOCAL_ONLY
|
||||||
gallery_categories = [
|
gallery_categories = [
|
||||||
ItemCategory.Book,
|
ItemCategory.Book,
|
||||||
ItemCategory.Movie,
|
ItemCategory.Movie,
|
||||||
|
@ -165,36 +165,39 @@ class DiscoverGenerator(BaseJob):
|
||||||
tags = TagManager.popular_tags(days=14, local_only=local)[:40]
|
tags = TagManager.popular_tags(days=14, local_only=local)[:40]
|
||||||
excluding_identities = Takahe.get_no_discover_identities()
|
excluding_identities = Takahe.get_no_discover_identities()
|
||||||
|
|
||||||
reviews = (
|
if settings.NEODB_DISCOVER_SHOW_POPULAR_POSTS:
|
||||||
Review.objects.filter(visibility=0)
|
reviews = (
|
||||||
.exclude(owner_id__in=excluding_identities)
|
Review.objects.filter(visibility=0)
|
||||||
.order_by("-created_time")
|
.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]
|
|
||||||
)
|
)
|
||||||
| set(
|
if local:
|
||||||
Takahe.get_popular_posts(
|
reviews = reviews.filter(local=True)
|
||||||
14, settings.MIN_MARKS_FOR_DISCOVER, excluding_identities, local
|
post_ids = (
|
||||||
).values_list("pk", flat=True)[:5]
|
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(
|
else:
|
||||||
Takahe.get_popular_posts(
|
post_ids = []
|
||||||
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])
|
|
||||||
)
|
|
||||||
cache.set("public_gallery", gallery_list, timeout=None)
|
cache.set("public_gallery", gallery_list, timeout=None)
|
||||||
cache.set("trends_links", trends, timeout=None)
|
cache.set("trends_links", trends, timeout=None)
|
||||||
cache.set("featured_collections", collection_ids, timeout=None)
|
cache.set("featured_collections", collection_ids, timeout=None)
|
||||||
|
|
|
@ -87,9 +87,9 @@
|
||||||
<li class="card">
|
<li class="card">
|
||||||
<a href="{{ item.url }}" title="{{ item.display_title }}">
|
<a href="{{ item.url }}" title="{{ item.display_title }}">
|
||||||
<img src="{{ item.cover|thumb:'normal' }}"
|
<img src="{{ item.cover|thumb:'normal' }}"
|
||||||
alt="{{ item.display_title }}"
|
alt="{{ item.title }}"
|
||||||
loading="lazy">
|
loading="lazy">
|
||||||
<div class="card-title">{{ item.display_title }}</div>
|
<div class="card-title">{{ item.title }}</div>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -263,8 +263,13 @@ def discover(request):
|
||||||
layout = request.user.preference.discover_layout
|
layout = request.user.preference.discover_layout
|
||||||
identity = request.user.identity
|
identity = request.user.identity
|
||||||
announcements = []
|
announcements = []
|
||||||
post_ids = cache.get("popular_posts", [])
|
if settings.DISCOVER_SHOW_POPULAR_POSTS:
|
||||||
popular_posts = Takahe.get_posts(post_ids).order_by("-published")
|
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:
|
else:
|
||||||
identity = None
|
identity = None
|
||||||
layout = []
|
layout = []
|
||||||
|
|
|
@ -34,8 +34,10 @@ x-shared:
|
||||||
NEODB_DISABLE_CRON_JOBS:
|
NEODB_DISABLE_CRON_JOBS:
|
||||||
NEODB_SEARCH_PEERS:
|
NEODB_SEARCH_PEERS:
|
||||||
NEODB_MIN_MARKS_FOR_DISCOVER:
|
NEODB_MIN_MARKS_FOR_DISCOVER:
|
||||||
NEODB_FILTER_LANGUAGE_FOR_DISCOVER:
|
NEODB_DISCOVER_UPDATE_INTERVAL:
|
||||||
NEODB_FILTER_LOCAL_ONLY_FOR_DISCOVER:
|
NEODB_DISCOVER_FILTER_LANGUAGE:
|
||||||
|
NEODB_DISCOVER_SHOW_LOCAL_ONLY:
|
||||||
|
NEODB_DISCOVER_SHOW_POPULAR_POSTS:
|
||||||
NEODB_SENTRY_DSN:
|
NEODB_SENTRY_DSN:
|
||||||
TAKAHE_SENTRY_DSN:
|
TAKAHE_SENTRY_DSN:
|
||||||
NEODB_SENTRY_SAMPLE_RATE:
|
NEODB_SENTRY_SAMPLE_RATE:
|
||||||
|
|
|
@ -25,8 +25,9 @@ if you are doing debug or development:
|
||||||
- `NEODB_SITE_HEAD`
|
- `NEODB_SITE_HEAD`
|
||||||
- `NEODB_SITE_DESCRIPTION`
|
- `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_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_DISCOVER_FILTER_LANGUAGE` - `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_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_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_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"
|
- `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)
|
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
|
@staticmethod
|
||||||
def get_popular_posts(
|
def get_popular_posts(
|
||||||
days: int = 30,
|
days: int = 30,
|
||||||
|
|
Loading…
Add table
Reference in a new issue