Merge branch 'nodeinfo-improvements' into 'develop'
Nodeinfo improvements See merge request funkwhale/funkwhale!545
This commit is contained in:
commit
385bc29705
|
@ -17,7 +17,7 @@ def get():
|
||||||
"protocols": ["activitypub"],
|
"protocols": ["activitypub"],
|
||||||
"services": {"inbound": [], "outbound": []},
|
"services": {"inbound": [], "outbound": []},
|
||||||
"openRegistrations": preferences.get("users__registration_enabled"),
|
"openRegistrations": preferences.get("users__registration_enabled"),
|
||||||
"usage": {"users": {"total": 0}},
|
"usage": {"users": {"total": 0, "activeHalfyear": 0, "activeMonth": 0}},
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"private": preferences.get("instance__nodeinfo_private"),
|
"private": preferences.get("instance__nodeinfo_private"),
|
||||||
"shortDescription": preferences.get("instance__short_description"),
|
"shortDescription": preferences.get("instance__short_description"),
|
||||||
|
@ -28,7 +28,7 @@ def get():
|
||||||
"federationNeedsApproval": preferences.get(
|
"federationNeedsApproval": preferences.get(
|
||||||
"federation__music_needs_approval"
|
"federation__music_needs_approval"
|
||||||
),
|
),
|
||||||
"anonymousCanListen": preferences.get(
|
"anonymousCanListen": not preferences.get(
|
||||||
"common__api_authentication_required"
|
"common__api_authentication_required"
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
@ -37,7 +37,11 @@ def get():
|
||||||
if share_stats:
|
if share_stats:
|
||||||
getter = memo(lambda: stats.get(), max_age=600)
|
getter = memo(lambda: stats.get(), max_age=600)
|
||||||
statistics = getter()
|
statistics = getter()
|
||||||
data["usage"]["users"]["total"] = statistics["users"]
|
data["usage"]["users"]["total"] = statistics["users"]["total"]
|
||||||
|
data["usage"]["users"]["activeHalfyear"] = statistics["users"][
|
||||||
|
"active_halfyear"
|
||||||
|
]
|
||||||
|
data["usage"]["users"]["activeMonth"] = statistics["users"]["active_month"]
|
||||||
data["metadata"]["library"]["tracks"] = {"total": statistics["tracks"]}
|
data["metadata"]["library"]["tracks"] = {"total": statistics["tracks"]}
|
||||||
data["metadata"]["library"]["artists"] = {"total": statistics["artists"]}
|
data["metadata"]["library"]["artists"] = {"total": statistics["artists"]}
|
||||||
data["metadata"]["library"]["albums"] = {"total": statistics["albums"]}
|
data["metadata"]["library"]["albums"] = {"total": statistics["albums"]}
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
import datetime
|
||||||
|
|
||||||
from django.db.models import Sum
|
from django.db.models import Sum
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
from funkwhale_api.favorites.models import TrackFavorite
|
from funkwhale_api.favorites.models import TrackFavorite
|
||||||
from funkwhale_api.history.models import Listening
|
from funkwhale_api.history.models import Listening
|
||||||
|
@ -19,6 +22,15 @@ def get():
|
||||||
|
|
||||||
|
|
||||||
def get_users():
|
def get_users():
|
||||||
|
qs = User.objects.filter(is_active=True)
|
||||||
|
now = timezone.now()
|
||||||
|
active_month = now - datetime.timedelta(days=30)
|
||||||
|
active_halfyear = now - datetime.timedelta(days=30 * 6)
|
||||||
|
return {
|
||||||
|
"total": qs.count(),
|
||||||
|
"active_month": qs.filter(last_activity__gte=active_month).count(),
|
||||||
|
"active_halfyear": qs.filter(last_activity__gte=active_halfyear).count(),
|
||||||
|
}
|
||||||
return User.objects.count()
|
return User.objects.count()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ from funkwhale_api.instance import nodeinfo
|
||||||
def test_nodeinfo_dump(preferences, mocker):
|
def test_nodeinfo_dump(preferences, mocker):
|
||||||
preferences["instance__nodeinfo_stats_enabled"] = True
|
preferences["instance__nodeinfo_stats_enabled"] = True
|
||||||
stats = {
|
stats = {
|
||||||
"users": 1,
|
"users": {"total": 1, "active_halfyear": 12, "active_month": 13},
|
||||||
"tracks": 2,
|
"tracks": 2,
|
||||||
"albums": 3,
|
"albums": 3,
|
||||||
"artists": 4,
|
"artists": 4,
|
||||||
|
@ -21,7 +21,7 @@ def test_nodeinfo_dump(preferences, mocker):
|
||||||
"protocols": ["activitypub"],
|
"protocols": ["activitypub"],
|
||||||
"services": {"inbound": [], "outbound": []},
|
"services": {"inbound": [], "outbound": []},
|
||||||
"openRegistrations": preferences["users__registration_enabled"],
|
"openRegistrations": preferences["users__registration_enabled"],
|
||||||
"usage": {"users": {"total": stats["users"]}},
|
"usage": {"users": {"total": 1, "activeHalfyear": 12, "activeMonth": 13}},
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"private": preferences["instance__nodeinfo_private"],
|
"private": preferences["instance__nodeinfo_private"],
|
||||||
"shortDescription": preferences["instance__short_description"],
|
"shortDescription": preferences["instance__short_description"],
|
||||||
|
@ -32,7 +32,7 @@ def test_nodeinfo_dump(preferences, mocker):
|
||||||
"federationNeedsApproval": preferences[
|
"federationNeedsApproval": preferences[
|
||||||
"federation__music_needs_approval"
|
"federation__music_needs_approval"
|
||||||
],
|
],
|
||||||
"anonymousCanListen": preferences[
|
"anonymousCanListen": not preferences[
|
||||||
"common__api_authentication_required"
|
"common__api_authentication_required"
|
||||||
],
|
],
|
||||||
"tracks": {"total": stats["tracks"]},
|
"tracks": {"total": stats["tracks"]},
|
||||||
|
@ -58,7 +58,7 @@ def test_nodeinfo_dump_stats_disabled(preferences, mocker):
|
||||||
"protocols": ["activitypub"],
|
"protocols": ["activitypub"],
|
||||||
"services": {"inbound": [], "outbound": []},
|
"services": {"inbound": [], "outbound": []},
|
||||||
"openRegistrations": preferences["users__registration_enabled"],
|
"openRegistrations": preferences["users__registration_enabled"],
|
||||||
"usage": {"users": {"total": 0}},
|
"usage": {"users": {"total": 0, "activeHalfyear": 0, "activeMonth": 0}},
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"private": preferences["instance__nodeinfo_private"],
|
"private": preferences["instance__nodeinfo_private"],
|
||||||
"shortDescription": preferences["instance__short_description"],
|
"shortDescription": preferences["instance__short_description"],
|
||||||
|
@ -69,7 +69,7 @@ def test_nodeinfo_dump_stats_disabled(preferences, mocker):
|
||||||
"federationNeedsApproval": preferences[
|
"federationNeedsApproval": preferences[
|
||||||
"federation__music_needs_approval"
|
"federation__music_needs_approval"
|
||||||
],
|
],
|
||||||
"anonymousCanListen": preferences[
|
"anonymousCanListen": not preferences[
|
||||||
"common__api_authentication_required"
|
"common__api_authentication_required"
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
|
import datetime
|
||||||
|
|
||||||
from funkwhale_api.instance import stats
|
from funkwhale_api.instance import stats
|
||||||
|
|
||||||
|
|
||||||
def test_get_users(mocker):
|
def test_get_users(factories, now):
|
||||||
mocker.patch("funkwhale_api.users.models.User.objects.count", return_value=42)
|
factories["users.User"](last_activity=now)
|
||||||
|
factories["users.User"](last_activity=now - datetime.timedelta(days=29))
|
||||||
assert stats.get_users() == 42
|
factories["users.User"](last_activity=now - datetime.timedelta(days=31))
|
||||||
|
factories["users.User"](last_activity=now - datetime.timedelta(days=190))
|
||||||
|
factories["users.User"](is_active=False)
|
||||||
|
assert stats.get_users() == {"total": 4, "active_month": 2, "active_halfyear": 3}
|
||||||
|
|
||||||
|
|
||||||
def test_get_music_duration(factories):
|
def test_get_music_duration(factories):
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import {expect} from 'chai'
|
import {expect} from 'chai'
|
||||||
var sinon = require('sinon')
|
var sinon = require('sinon')
|
||||||
|
import axios from 'axios'
|
||||||
import moxios from 'moxios'
|
import moxios from 'moxios'
|
||||||
import store from '@/store/instance'
|
import store from '@/store/instance'
|
||||||
import { testAction } from '../../utils'
|
import { testAction } from '../../utils'
|
||||||
|
@ -14,6 +15,7 @@ describe('store/instance', () => {
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
sandbox.restore()
|
sandbox.restore()
|
||||||
moxios.uninstall()
|
moxios.uninstall()
|
||||||
|
axios.defaults.baseURL = null
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('mutations', () => {
|
describe('mutations', () => {
|
||||||
|
|
Loading…
Reference in New Issue