Skip to content

Commit

Permalink
! Rename subscriptions to subscription cache & fix outdated mutation …
Browse files Browse the repository at this point in the history
…reference
  • Loading branch information
PikachuEXE committed Jun 5, 2024
1 parent 0f2c338 commit 80c322b
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 94 deletions.
8 changes: 4 additions & 4 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ const IpcChannels = {
DB_HISTORY: 'db-history',
DB_PROFILES: 'db-profiles',
DB_PLAYLISTS: 'db-playlists',
DB_SUBSCRIPTIONS: 'db-subscriptions',
DB_SUBSCRIPTION_CACHE: 'db-subscription-cache',

SYNC_SETTINGS: 'sync-settings',
SYNC_HISTORY: 'sync-history',
SYNC_PROFILES: 'sync-profiles',
SYNC_PLAYLISTS: 'sync-playlists',
SYNC_SUBSCRIPTIONS: 'sync-subscriptions',
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 @@ -68,7 +68,7 @@ const DBActions = {
DELETE_ALL_VIDEOS: 'db-action-playlists-delete-all-videos',
},

SUBSCRIPTIONS: {
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',
Expand All @@ -95,7 +95,7 @@ const SyncEvents = {
DELETE_VIDEO: 'sync-playlists-delete-video',
},

SUBSCRIPTIONS: {
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',
Expand Down
24 changes: 12 additions & 12 deletions src/datastores/handlers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,37 +167,37 @@ class Playlists {
}
}

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

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

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

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

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

const shorts = doc.shorts
Expand All @@ -221,7 +221,7 @@ class Subscriptions {
}
})

return db.subscriptions.updateAsync(
return db.subscriptionCache.updateAsync(
{ _id: channelId },
{ $set: { shorts: cacheShorts } },
{ upsert: true }
Expand All @@ -230,19 +230,19 @@ class Subscriptions {
}

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

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

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

Expand All @@ -252,7 +252,7 @@ function compactAllDatastores() {
db.history.compactDatafileAsync(),
db.profiles.compactDatafileAsync(),
db.playlists.compactDatafileAsync(),
db.subscriptions.compactDatafileAsync(),
db.subscriptionCache.compactDatafileAsync(),
])
}

Expand All @@ -261,7 +261,7 @@ export {
History as history,
Profiles as profiles,
Playlists as playlists,
Subscriptions as subscriptions,
SubscriptionCache as subscriptionCache,

compactAllDatastores,
}
30 changes: 15 additions & 15 deletions src/datastores/handlers/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,74 +191,74 @@ class Playlists {
}
}

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

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

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

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

static updateShortsWithChannelPageShortsByChannelId({ channelId, entries }) {
return ipcRenderer.invoke(
IpcChannels.DB_SUBSCRIPTIONS,
IpcChannels.DB_SUBSCRIPTION_CACHE,
{
action: DBActions.SUBSCRIPTIONS.UPDATE_SHORTS_WITH_CHANNEL_PAGE_SHORTS_BY_CHANNEL,
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_SUBSCRIPTIONS,
IpcChannels.DB_SUBSCRIPTION_CACHE,
{
action: DBActions.SUBSCRIPTIONS.UPDATE_COMMUNITY_POSTS_BY_CHANNEL,
action: DBActions.SUBSCRIPTION_CACHE.UPDATE_COMMUNITY_POSTS_BY_CHANNEL,
data: { channelId, entries, timestamp },
}
)
}

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

static deleteAll() {
return ipcRenderer.invoke(
IpcChannels.DB_SUBSCRIPTIONS,
IpcChannels.DB_SUBSCRIPTION_CACHE,
{ action: DBActions.GENERAL.DELETE_ALL }
)
}
Expand All @@ -269,5 +269,5 @@ export {
History as history,
Profiles as profiles,
Playlists as playlists,
Subscriptions as subscriptions,
SubscriptionCache as subscriptionCache,
}
2 changes: 1 addition & 1 deletion src/datastores/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export {
history as DBHistoryHandlers,
profiles as DBProfileHandlers,
playlists as DBPlaylistHandlers,
subscriptions as DBSubscriptionsHandlers,
subscriptionCache as DBSubscriptionCacheHandlers,
} from 'DB_HANDLERS_ELECTRON_RENDERER_OR_WEB'
20 changes: 10 additions & 10 deletions src/datastores/handlers/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,56 +110,56 @@ class Playlists {
}
}

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

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

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

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

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

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

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

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

Expand All @@ -168,5 +168,5 @@ export {
History as history,
Profiles as profiles,
Playlists as playlists,
Subscriptions as subscriptions,
SubscriptionCache as subscriptionCache,
}
2 changes: 1 addition & 1 deletion src/datastores/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +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 subscriptions = new Datastore({ filename: dbPath('subscriptions'), autoload: true })
export const subscriptionCache = new Datastore({ filename: dbPath('subscription-cache'), autoload: true })
Loading

0 comments on commit 80c322b

Please sign in to comment.