Reduce number of cache calls by retrieving multiple preferences at once in nodeinfo
This commit is contained in:
parent
3a9f2cde37
commit
01d2206001
|
@ -14,6 +14,11 @@ def get(pref):
|
||||||
return manager[pref]
|
return manager[pref]
|
||||||
|
|
||||||
|
|
||||||
|
def all():
|
||||||
|
manager = global_preferences_registry.manager()
|
||||||
|
return manager.all()
|
||||||
|
|
||||||
|
|
||||||
def set(pref, value):
|
def set(pref, value):
|
||||||
manager = global_preferences_registry.manager()
|
manager = global_preferences_registry.manager()
|
||||||
manager[pref] = value
|
manager[pref] = value
|
||||||
|
|
|
@ -13,10 +13,11 @@ memo = memoize.Memoizer(store, namespace="instance:stats")
|
||||||
|
|
||||||
|
|
||||||
def get():
|
def get():
|
||||||
share_stats = preferences.get("instance__nodeinfo_stats_enabled")
|
all_preferences = preferences.all()
|
||||||
allow_list_enabled = preferences.get("moderation__allow_list_enabled")
|
share_stats = all_preferences.get("instance__nodeinfo_stats_enabled")
|
||||||
allow_list_public = preferences.get("moderation__allow_list_public")
|
allow_list_enabled = all_preferences.get("moderation__allow_list_enabled")
|
||||||
unauthenticated_report_types = preferences.get(
|
allow_list_public = all_preferences.get("moderation__allow_list_public")
|
||||||
|
unauthenticated_report_types = all_preferences.get(
|
||||||
"moderation__unauthenticated_report_types"
|
"moderation__unauthenticated_report_types"
|
||||||
)
|
)
|
||||||
if allow_list_enabled and allow_list_public:
|
if allow_list_enabled and allow_list_public:
|
||||||
|
@ -32,20 +33,20 @@ def get():
|
||||||
"software": {"name": "funkwhale", "version": funkwhale_api.__version__},
|
"software": {"name": "funkwhale", "version": funkwhale_api.__version__},
|
||||||
"protocols": ["activitypub"],
|
"protocols": ["activitypub"],
|
||||||
"services": {"inbound": [], "outbound": []},
|
"services": {"inbound": [], "outbound": []},
|
||||||
"openRegistrations": preferences.get("users__registration_enabled"),
|
"openRegistrations": all_preferences.get("users__registration_enabled"),
|
||||||
"usage": {"users": {"total": 0, "activeHalfyear": 0, "activeMonth": 0}},
|
"usage": {"users": {"total": 0, "activeHalfyear": 0, "activeMonth": 0}},
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"actorId": actors.get_service_actor().fid,
|
"actorId": actors.get_service_actor().fid,
|
||||||
"private": preferences.get("instance__nodeinfo_private"),
|
"private": all_preferences.get("instance__nodeinfo_private"),
|
||||||
"shortDescription": preferences.get("instance__short_description"),
|
"shortDescription": all_preferences.get("instance__short_description"),
|
||||||
"longDescription": preferences.get("instance__long_description"),
|
"longDescription": all_preferences.get("instance__long_description"),
|
||||||
"nodeName": preferences.get("instance__name"),
|
"nodeName": all_preferences.get("instance__name"),
|
||||||
"library": {
|
"library": {
|
||||||
"federationEnabled": preferences.get("federation__enabled"),
|
"federationEnabled": all_preferences.get("federation__enabled"),
|
||||||
"federationNeedsApproval": preferences.get(
|
"federationNeedsApproval": all_preferences.get(
|
||||||
"federation__music_needs_approval"
|
"federation__music_needs_approval"
|
||||||
),
|
),
|
||||||
"anonymousCanListen": not preferences.get(
|
"anonymousCanListen": not all_preferences.get(
|
||||||
"common__api_authentication_required"
|
"common__api_authentication_required"
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue