change: offload item loading to server

This commit is contained in:
benonymity 2022-09-03 16:12:00 -04:00
parent 0125f9b3ad
commit 9bb63a1dff
2 changed files with 10 additions and 15 deletions

View file

@ -18,13 +18,13 @@
<template v-for="(user, num) in users">
<div :key="user.username" class="w-full">
<div class="flex items-center mb-1">
<nuxt-link :to="`/item/${user.latest.libraryItemId}`">
<ui-tooltip direction="left" :text="Math.round(user.latest.progress * 100) + '%'">
<covers-book-cover class="absolute left-0 right-0" :library-item="user.libraryItem" :width="bookCoverWidth" :book-cover-aspect-ratio="bookCoverAspectRatio" />
<nuxt-link :to="`/item/${user.latest.progress.libraryItemId}`">
<ui-tooltip direction="left" :text="Math.round(user.latest.progress.progress * 100) + '%'">
<covers-book-cover class="absolute left-0 right-0" :library-item="user.latest.item" :width="bookCoverWidth" :book-cover-aspect-ratio="bookCoverAspectRatio" />
</ui-tooltip>
</nuxt-link>
<p class="text-lg px-2 font-book text-white">{{ user.username }}&nbsp;</p>
<p class="text-xs text-white text-opacity-50">{{ "Last listened " + $dateDistanceFromNow(user.latest.lastUpdate) }}</p>
<p class="text-xs text-white text-opacity-50">{{ "Last listened " + $dateDistanceFromNow(user.latest.progress.lastUpdate) }}</p>
<div class="flex-grow" />
<div class="w-30 pl-4 text-right">
<p class="text-sm font-bold">{{ "Has listened for " + $elapsedPrettyExtended(user.minutesListened) }}</p>
@ -61,7 +61,7 @@ export default {
},
users() {
if (!this.listeningStats) return []
return this.listeningStats.sort(function(a, b) {return b.latest.lastUpdate - a.latest.lastUpdate})
return this.listeningStats.sort(function(a, b) {return b.latest.progress.lastUpdate - a.latest.progress.lastUpdate})
},
usersOnline() {
var usermap = {}
@ -82,15 +82,6 @@ export default {
console.error('Failed to load shared user listening sesions', err)
return []
})
for (let i = 0; i < listeningStats.length; i++) {
if (listeningStats[i].latest != null) {
listeningStats[i].libraryItem = await this.$axios
.$get(`/api/items/${listeningStats[i].latest.libraryItemId}`)
.catch((error) => {
console.error('Failed', error)
})
}
}
this.listeningStats = listeningStats
},
changeSharingSetting() {

View file

@ -271,10 +271,14 @@ class MiscController {
var latestItem = user.mediaProgress.sort(p => p.lastUpdate)
var totalItems = Object.keys(listeningStats.items).length
var totalDays = Object.keys(listeningStats.days).length
var latestProgress = latestItem[latestItem.length - 1]
if (latestProgress) {
var latestItem = this.db.getLibraryItem(latestProgress.id)
}
var session = {
username: user.username,
lastSeen: user.lastSeen,
latest: latestItem[latestItem.length - 1] || null,
latest: {'progress': latestProgress, 'item': latestItem} || null,
itemsRead: totalItems || 0,
minutesListened: listeningStats.totalTime || 0,
daysListened: totalDays| 0,