Skip to content

Commit

Permalink
Merge branch 'development' into feature/history/remember-search-query
Browse files Browse the repository at this point in the history
* development:
  Fix video start time handling (FreeTubeApp#5719)
  Local API: Handle new shorts node (FreeTubeApp#5679)
  Update subscription cache when subscribing from the channel page (FreeTubeApp#5717)
  Translated using Weblate (English (United Kingdom))
  Implement persistent subscription cache (FreeTubeApp#5185)
  Translated using Weblate (Belarusian)
  Bump npm-run-all2 from 6.2.2 to 6.2.3 (FreeTubeApp#5708)
  Translated using Weblate (Swedish)
  Bump shaka-player from 4.11.1 to 4.11.3 (FreeTubeApp#5707)
  Translated using Weblate (Persian)
  v Downgrade electron-builder 25.x > 24.x (FreeTubeApp#5712)
  Translated using Weblate (Persian)
  Translated using Weblate (Persian)

# Conflicts:
#	src/renderer/views/Channel/Channel.js
#	src/renderer/views/Channel/Channel.vue
  • Loading branch information
PikachuEXE committed Sep 21, 2024
2 parents 47222b9 + 9ca2c74 commit ce7c712
Show file tree
Hide file tree
Showing 34 changed files with 1,114 additions and 1,005 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@
"path-browserify": "^1.0.1",
"portal-vue": "^2.1.7",
"process": "^0.11.10",
"shaka-player": "^4.11.1",
"shaka-player": "^4.11.3",
"swiper": "^11.1.14",
"vue": "^2.7.16",
"vue-i18n": "^8.28.2",
"vue-observe-visibility": "^1.0.0",
"vue-router": "^3.6.5",
"vuex": "^3.6.2",
"youtubei.js": "^10.4.0"
"youtubei.js": "^10.5.0"
},
"devDependencies": {
"@babel/core": "^7.25.2",
Expand All @@ -88,7 +88,7 @@
"css-loader": "^7.1.2",
"css-minimizer-webpack-plugin": "^7.0.0",
"electron": "^32.1.0",
"electron-builder": "^25.0.5",
"electron-builder": "^24.13.3",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard": "^17.1.0",
Expand All @@ -106,7 +106,7 @@
"json-minimizer-webpack-plugin": "^5.0.0",
"lefthook": "^1.7.15",
"mini-css-extract-plugin": "^2.9.1",
"npm-run-all2": "^6.2.2",
"npm-run-all2": "^6.2.3",
"postcss": "^8.4.47",
"postcss-scss": "^4.0.9",
"prettier": "^2.8.8",
Expand Down
22 changes: 20 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ const IpcChannels = {
DB_HISTORY: 'db-history',
DB_PROFILES: 'db-profiles',
DB_PLAYLISTS: 'db-playlists',
DB_SUBSCRIPTION_CACHE: 'db-subscription-cache',

SYNC_SETTINGS: 'sync-settings',
SYNC_HISTORY: 'sync-history',
SYNC_PROFILES: 'sync-profiles',
SYNC_PLAYLISTS: 'sync-playlists',
SYNC_SUBSCRIPTION_CACHE: 'sync-subscription-cache',

GET_REPLACE_HTTP_CACHE: 'get-replace-http-cache',
TOGGLE_REPLACE_HTTP_CACHE: 'toggle-replace-http-cache',
Expand Down Expand Up @@ -67,7 +69,15 @@ const DBActions = {
DELETE_VIDEO_ID: 'db-action-playlists-delete-video-by-playlist-name',
DELETE_VIDEO_IDS: 'db-action-playlists-delete-video-ids',
DELETE_ALL_VIDEOS: 'db-action-playlists-delete-all-videos',
}
},

SUBSCRIPTION_CACHE: {
UPDATE_VIDEOS_BY_CHANNEL: 'db-action-subscriptions-update-videos-by-channel',
UPDATE_LIVE_STREAMS_BY_CHANNEL: 'db-action-subscriptions-update-live-streams-by-channel',
UPDATE_SHORTS_BY_CHANNEL: 'db-action-subscriptions-update-shorts-by-channel',
UPDATE_SHORTS_WITH_CHANNEL_PAGE_SHORTS_BY_CHANNEL: 'db-action-subscriptions-update-shorts-with-channel-page-shorts-by-channel',
UPDATE_COMMUNITY_POSTS_BY_CHANNEL: 'db-action-subscriptions-update-community-posts-by-channel',
},
}

const SyncEvents = {
Expand All @@ -92,7 +102,15 @@ const SyncEvents = {
PLAYLISTS: {
UPSERT_VIDEO: 'sync-playlists-upsert-video',
DELETE_VIDEO: 'sync-playlists-delete-video',
}
},

SUBSCRIPTION_CACHE: {
UPDATE_VIDEOS_BY_CHANNEL: 'sync-subscriptions-update-videos-by-channel',
UPDATE_LIVE_STREAMS_BY_CHANNEL: 'sync-subscriptions-update-live-streams-by-channel',
UPDATE_SHORTS_BY_CHANNEL: 'sync-subscriptions-update-shorts-by-channel',
UPDATE_SHORTS_WITH_CHANNEL_PAGE_SHORTS_BY_CHANNEL: 'sync-subscriptions-update-shorts-with-channel-page-shorts-by-channel',
UPDATE_COMMUNITY_POSTS_BY_CHANNEL: 'sync-subscriptions-update-community-posts-by-channel',
},
}

// Utils
Expand Down
81 changes: 81 additions & 0 deletions src/datastores/handlers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,92 @@ class Playlists {
}
}

class SubscriptionCache {
static find() {
return db.subscriptionCache.findAsync({})
}

static updateVideosByChannelId({ channelId, entries, timestamp }) {
return db.subscriptionCache.updateAsync(
{ _id: channelId },
{ $set: { videos: entries, videosTimestamp: timestamp } },
{ upsert: true }
)
}

static updateLiveStreamsByChannelId({ channelId, entries, timestamp }) {
return db.subscriptionCache.updateAsync(
{ _id: channelId },
{ $set: { liveStreams: entries, liveStreamsTimestamp: timestamp } },
{ upsert: true }
)
}

static updateShortsByChannelId({ channelId, entries, timestamp }) {
return db.subscriptionCache.updateAsync(
{ _id: channelId },
{ $set: { shorts: entries, shortsTimestamp: timestamp } },
{ upsert: true }
)
}

static updateShortsWithChannelPageShortsByChannelId({ channelId, entries }) {
return db.subscriptionCache.findOneAsync({ _id: channelId }, { shorts: 1 }).then((doc) => {
if (doc == null) { return }

const shorts = doc.shorts
const cacheShorts = Array.isArray(shorts) ? shorts : []

cacheShorts.forEach(cachedVideo => {
const channelVideo = entries.find(short => cachedVideo.videoId === short.videoId)
if (!channelVideo) { return }

// authorId probably never changes, so we don't need to update that
cachedVideo.title = channelVideo.title
cachedVideo.author = channelVideo.author

// as the channel shorts page only has compact view counts for numbers above 1000 e.g. 12k
// and the RSS feeds include an exact value, we only want to overwrite it when the number is larger than the cached value
// 12345 vs 12000 => 12345
// 12345 vs 15000 => 15000

if (channelVideo.viewCount > cachedVideo.viewCount) {
cachedVideo.viewCount = channelVideo.viewCount
}
})

return db.subscriptionCache.updateAsync(
{ _id: channelId },
{ $set: { shorts: cacheShorts } },
{ upsert: true }
)
})
}

static updateCommunityPostsByChannelId({ channelId, entries, timestamp }) {
return db.subscriptionCache.updateAsync(
{ _id: channelId },
{ $set: { communityPosts: entries, communityPostsTimestamp: timestamp } },
{ upsert: true }
)
}

static deleteMultipleChannels(channelIds) {
return db.subscriptionCache.removeAsync({ _id: { $in: channelIds } }, { multi: true })
}

static deleteAll() {
return db.subscriptionCache.removeAsync({}, { multi: true })
}
}

function compactAllDatastores() {
return Promise.allSettled([
db.settings.compactDatafileAsync(),
db.history.compactDatafileAsync(),
db.profiles.compactDatafileAsync(),
db.playlists.compactDatafileAsync(),
db.subscriptionCache.compactDatafileAsync(),
])
}

Expand All @@ -217,6 +297,7 @@ export {
History as history,
Profiles as profiles,
Playlists as playlists,
SubscriptionCache as subscriptionCache,

compactAllDatastores,
}
76 changes: 75 additions & 1 deletion src/datastores/handlers/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,83 @@ class Playlists {
}
}

class SubscriptionCache {
static find() {
return ipcRenderer.invoke(
IpcChannels.DB_SUBSCRIPTION_CACHE,
{ action: DBActions.GENERAL.FIND }
)
}

static updateVideosByChannelId({ channelId, entries, timestamp }) {
return ipcRenderer.invoke(
IpcChannels.DB_SUBSCRIPTION_CACHE,
{
action: DBActions.SUBSCRIPTION_CACHE.UPDATE_VIDEOS_BY_CHANNEL,
data: { channelId, entries, timestamp },
}
)
}

static updateLiveStreamsByChannelId({ channelId, entries, timestamp }) {
return ipcRenderer.invoke(
IpcChannels.DB_SUBSCRIPTION_CACHE,
{
action: DBActions.SUBSCRIPTION_CACHE.UPDATE_LIVE_STREAMS_BY_CHANNEL,
data: { channelId, entries, timestamp },
}
)
}

static updateShortsByChannelId({ channelId, entries, timestamp }) {
return ipcRenderer.invoke(
IpcChannels.DB_SUBSCRIPTION_CACHE,
{
action: DBActions.SUBSCRIPTION_CACHE.UPDATE_SHORTS_BY_CHANNEL,
data: { channelId, entries, timestamp },
}
)
}

static updateShortsWithChannelPageShortsByChannelId({ channelId, entries }) {
return ipcRenderer.invoke(
IpcChannels.DB_SUBSCRIPTION_CACHE,
{
action: DBActions.SUBSCRIPTION_CACHE.UPDATE_SHORTS_WITH_CHANNEL_PAGE_SHORTS_BY_CHANNEL,
data: { channelId, entries },
}
)
}

static updateCommunityPostsByChannelId({ channelId, entries, timestamp }) {
return ipcRenderer.invoke(
IpcChannels.DB_SUBSCRIPTION_CACHE,
{
action: DBActions.SUBSCRIPTION_CACHE.UPDATE_COMMUNITY_POSTS_BY_CHANNEL,
data: { channelId, entries, timestamp },
}
)
}

static deleteMultipleChannels(channelIds) {
return ipcRenderer.invoke(
IpcChannels.DB_SUBSCRIPTION_CACHE,
{ action: DBActions.GENERAL.DELETE_MULTIPLE, data: channelIds }
)
}

static deleteAll() {
return ipcRenderer.invoke(
IpcChannels.DB_SUBSCRIPTION_CACHE,
{ action: DBActions.GENERAL.DELETE_ALL }
)
}
}

export {
Settings as settings,
History as history,
Profiles as profiles,
Playlists as playlists
Playlists as playlists,
SubscriptionCache as subscriptionCache,
}
3 changes: 2 additions & 1 deletion src/datastores/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export {
settings as DBSettingHandlers,
history as DBHistoryHandlers,
profiles as DBProfileHandlers,
playlists as DBPlaylistHandlers
playlists as DBPlaylistHandlers,
subscriptionCache as DBSubscriptionCacheHandlers,
} from 'DB_HANDLERS_ELECTRON_RENDERER_OR_WEB'
56 changes: 55 additions & 1 deletion src/datastores/handlers/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,63 @@ class Playlists {
}
}

class SubscriptionCache {
static find() {
return baseHandlers.subscriptionCache.find()
}

static updateVideosByChannelId({ channelId, entries, timestamp }) {
return baseHandlers.subscriptionCache.updateVideosByChannelId({
channelId,
entries,
timestamp,
})
}

static updateLiveStreamsByChannelId({ channelId, entries, timestamp }) {
return baseHandlers.subscriptionCache.updateLiveStreamsByChannelId({
channelId,
entries,
timestamp,
})
}

static updateShortsByChannelId({ channelId, entries, timestamp }) {
return baseHandlers.subscriptionCache.updateShortsByChannelId({
channelId,
entries,
timestamp,
})
}

static updateShortsWithChannelPageShortsByChannelId({ channelId, entries }) {
return baseHandlers.subscriptionCache.updateShortsWithChannelPageShortsByChannelId({
channelId,
entries,
})
}

static updateCommunityPostsByChannelId({ channelId, entries, timestamp }) {
return baseHandlers.subscriptionCache.updateCommunityPostsByChannelId({
channelId,
entries,
timestamp,
})
}

static deleteMultipleChannels(channelIds) {
return baseHandlers.subscriptionCache.deleteMultipleChannels(channelIds)
}

static deleteAll() {
return baseHandlers.subscriptionCache.deleteAll()
}
}

export {
Settings as settings,
History as history,
Profiles as profiles,
Playlists as playlists
Playlists as playlists,
SubscriptionCache as subscriptionCache,
}
1 change: 1 addition & 0 deletions src/datastores/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export const settings = new Datastore({ filename: dbPath('settings'), autoload:
export const profiles = new Datastore({ filename: dbPath('profiles'), autoload: true })
export const playlists = new Datastore({ filename: dbPath('playlists'), autoload: true })
export const history = new Datastore({ filename: dbPath('history'), autoload: true })
export const subscriptionCache = new Datastore({ filename: dbPath('subscription-cache'), autoload: true })
Loading

0 comments on commit ce7c712

Please sign in to comment.