aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-06-20 10:23:19 +0200
committerChocobozzz <me@florianbigard.com>2022-06-20 10:23:19 +0200
commit714e33a7428b71ef98129ce85a4bd64140bcd912 (patch)
tree59bd3e4b359bcd04f4ad97c404246688ccd84e68 /server
parentaa2ce188d102ab38452df316d06286040b5d9075 (diff)
parentd47b18079bfe4aed472ddcc0a89302ba85f03a48 (diff)
downloadPeerTube-714e33a7428b71ef98129ce85a4bd64140bcd912.tar.gz
PeerTube-714e33a7428b71ef98129ce85a4bd64140bcd912.tar.zst
PeerTube-714e33a7428b71ef98129ce85a4bd64140bcd912.zip
Merge branch 'release/4.2.0' into develop
Diffstat (limited to 'server')
-rw-r--r--server/initializers/constants.ts2
-rw-r--r--server/lib/views/shared/video-viewer-counters.ts2
-rw-r--r--server/models/account/account-blocklist.ts14
-rw-r--r--server/models/user/user.ts4
-rw-r--r--server/models/video/video-comment.ts4
-rw-r--r--server/models/video/video-playlist.ts4
-rw-r--r--server/tests/api/moderation/blocklist.ts28
-rw-r--r--server/tests/api/server/stats.ts4
8 files changed, 54 insertions, 8 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 52007d212..f54ce9506 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -370,7 +370,7 @@ const CONSTRAINTS_FIELDS = {
370 370
371const VIEW_LIFETIME = { 371const VIEW_LIFETIME = {
372 VIEW: CONFIG.VIEWS.VIDEOS.IP_VIEW_EXPIRATION, 372 VIEW: CONFIG.VIEWS.VIDEOS.IP_VIEW_EXPIRATION,
373 VIEWER_COUNTER: 60000 * 1, // 1 minute 373 VIEWER_COUNTER: 60000 * 2, // 2 minutes
374 VIEWER_STATS: 60000 * 60 // 1 hour 374 VIEWER_STATS: 60000 * 60 // 1 hour
375} 375}
376 376
diff --git a/server/lib/views/shared/video-viewer-counters.ts b/server/lib/views/shared/video-viewer-counters.ts
index 587621320..cf3fa5882 100644
--- a/server/lib/views/shared/video-viewer-counters.ts
+++ b/server/lib/views/shared/video-viewer-counters.ts
@@ -165,7 +165,7 @@ export class VideoViewerCounters {
165 private async federateViewerIfNeeded (video: MVideoImmutable, viewer: Viewer) { 165 private async federateViewerIfNeeded (video: MVideoImmutable, viewer: Viewer) {
166 // Federate the viewer if it's been a "long" time we did not 166 // Federate the viewer if it's been a "long" time we did not
167 const now = new Date().getTime() 167 const now = new Date().getTime()
168 const federationLimit = now - (VIEW_LIFETIME.VIEWER_COUNTER / 2) 168 const federationLimit = now - (VIEW_LIFETIME.VIEWER_COUNTER * 0.75)
169 169
170 if (viewer.lastFederation && viewer.lastFederation > federationLimit) return 170 if (viewer.lastFederation && viewer.lastFederation > federationLimit) return
171 171
diff --git a/server/models/account/account-blocklist.ts b/server/models/account/account-blocklist.ts
index a7b8db076..377249b38 100644
--- a/server/models/account/account-blocklist.ts
+++ b/server/models/account/account-blocklist.ts
@@ -132,6 +132,20 @@ export class AccountBlocklistModel extends Model<Partial<AttributesOnly<AccountB
132 as: 'BlockedAccount' 132 as: 'BlockedAccount'
133 } 133 }
134 ] 134 ]
135 } else if (search) { // We need some joins when counting with search
136 query.include = [
137 {
138 model: AccountModel.unscoped(),
139 required: true,
140 as: 'BlockedAccount',
141 include: [
142 {
143 model: ActorModel.unscoped(),
144 required: true
145 }
146 ]
147 }
148 ]
135 } 149 }
136 150
137 return query 151 return query
diff --git a/server/models/user/user.ts b/server/models/user/user.ts
index 20c2222a7..a25551ecd 100644
--- a/server/models/user/user.ts
+++ b/server/models/user/user.ts
@@ -819,10 +819,10 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> {
819 } 819 }
820 } 820 }
821 821
822 return UserModel.count(query) 822 return UserModel.unscoped().count(query)
823 } 823 }
824 824
825 const totalUsers = await UserModel.count() 825 const totalUsers = await UserModel.unscoped().count()
826 const totalDailyActiveUsers = await getActiveUsers(1) 826 const totalDailyActiveUsers = await getActiveUsers(1)
827 const totalWeeklyActiveUsers = await getActiveUsers(7) 827 const totalWeeklyActiveUsers = await getActiveUsers(7)
828 const totalMonthlyActiveUsers = await getActiveUsers(30) 828 const totalMonthlyActiveUsers = await getActiveUsers(30)
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 2d60c6a30..1d3178164 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -683,11 +683,11 @@ export class VideoCommentModel extends Model<Partial<AttributesOnly<VideoComment
683 const totalLocalVideoComments = await VideoCommentModel.count({ 683 const totalLocalVideoComments = await VideoCommentModel.count({
684 include: [ 684 include: [
685 { 685 {
686 model: AccountModel, 686 model: AccountModel.unscoped(),
687 required: true, 687 required: true,
688 include: [ 688 include: [
689 { 689 {
690 model: ActorModel, 690 model: ActorModel.unscoped(),
691 required: true, 691 required: true,
692 where: { 692 where: {
693 serverId: null 693 serverId: null
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts
index 8fb3d5f15..00cca0549 100644
--- a/server/models/video/video-playlist.ts
+++ b/server/models/video/video-playlist.ts
@@ -617,11 +617,11 @@ export class VideoPlaylistModel extends Model<Partial<AttributesOnly<VideoPlayli
617 const totalLocalPlaylists = await VideoPlaylistModel.count({ 617 const totalLocalPlaylists = await VideoPlaylistModel.count({
618 include: [ 618 include: [
619 { 619 {
620 model: AccountModel, 620 model: AccountModel.unscoped(),
621 required: true, 621 required: true,
622 include: [ 622 include: [
623 { 623 {
624 model: ActorModel, 624 model: ActorModel.unscoped(),
625 required: true, 625 required: true,
626 where: { 626 where: {
627 serverId: null 627 serverId: null
diff --git a/server/tests/api/moderation/blocklist.ts b/server/tests/api/moderation/blocklist.ts
index e1344a245..a5a92317d 100644
--- a/server/tests/api/moderation/blocklist.ts
+++ b/server/tests/api/moderation/blocklist.ts
@@ -256,6 +256,13 @@ describe('Test blocklist', function () {
256 } 256 }
257 }) 257 })
258 258
259 it('Should search blocked accounts', async function () {
260 const body = await command.listMyAccountBlocklist({ start: 0, count: 10, search: 'user2' })
261 expect(body.total).to.equal(1)
262
263 expect(body.data[0].blockedAccount.name).to.equal('user2')
264 })
265
259 it('Should get blocked status', async function () { 266 it('Should get blocked status', async function () {
260 const remoteHandle = 'user2@' + servers[1].host 267 const remoteHandle = 'user2@' + servers[1].host
261 const localHandle = 'user1@' + servers[0].host 268 const localHandle = 'user1@' + servers[0].host
@@ -475,6 +482,13 @@ describe('Test blocklist', function () {
475 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) 482 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
476 }) 483 })
477 484
485 it('Should search blocked servers', async function () {
486 const body = await command.listMyServerBlocklist({ start: 0, count: 10, search: servers[1].host })
487 expect(body.total).to.equal(1)
488
489 expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
490 })
491
478 it('Should get blocklist status', async function () { 492 it('Should get blocklist status', async function () {
479 const blockedServer = servers[1].host 493 const blockedServer = servers[1].host
480 const notBlockedServer = 'example.com' 494 const notBlockedServer = 'example.com'
@@ -645,6 +659,13 @@ describe('Test blocklist', function () {
645 } 659 }
646 }) 660 })
647 661
662 it('Should search blocked accounts', async function () {
663 const body = await command.listServerAccountBlocklist({ start: 0, count: 10, search: 'user2' })
664 expect(body.total).to.equal(1)
665
666 expect(body.data[0].blockedAccount.name).to.equal('user2')
667 })
668
648 it('Should get blocked status', async function () { 669 it('Should get blocked status', async function () {
649 const remoteHandle = 'user2@' + servers[1].host 670 const remoteHandle = 'user2@' + servers[1].host
650 const localHandle = 'user1@' + servers[0].host 671 const localHandle = 'user1@' + servers[0].host
@@ -805,6 +826,13 @@ describe('Test blocklist', function () {
805 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port) 826 expect(block.blockedServer.host).to.equal('localhost:' + servers[1].port)
806 }) 827 })
807 828
829 it('Should search blocked servers', async function () {
830 const body = await command.listServerServerBlocklist({ start: 0, count: 10, search: servers[1].host })
831 expect(body.total).to.equal(1)
832
833 expect(body.data[0].blockedServer.host).to.equal(servers[1].host)
834 })
835
808 it('Should get blocklist status', async function () { 836 it('Should get blocklist status', async function () {
809 const blockedServer = servers[1].host 837 const blockedServer = servers[1].host
810 const notBlockedServer = 'example.com' 838 const notBlockedServer = 'example.com'
diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts
index a9ae236fb..6654eaaee 100644
--- a/server/tests/api/server/stats.ts
+++ b/server/tests/api/server/stats.ts
@@ -10,6 +10,8 @@ import {
10 doubleFollow, 10 doubleFollow,
11 PeerTubeServer, 11 PeerTubeServer,
12 setAccessTokensToServers, 12 setAccessTokensToServers,
13 setDefaultAccountAvatar,
14 setDefaultChannelAvatar,
13 waitJobs 15 waitJobs
14} from '@shared/server-commands' 16} from '@shared/server-commands'
15 17
@@ -29,6 +31,8 @@ describe('Test stats (excluding redundancy)', function () {
29 servers = await createMultipleServers(3) 31 servers = await createMultipleServers(3)
30 32
31 await setAccessTokensToServers(servers) 33 await setAccessTokensToServers(servers)
34 await setDefaultChannelAvatar(servers)
35 await setDefaultAccountAvatar(servers)
32 36
33 await doubleFollow(servers[0], servers[1]) 37 await doubleFollow(servers[0], servers[1])
34 38