From de8a9304d21dc53b607beee4396e3abf685652ac Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 15 Dec 2024 17:05:57 -0600 Subject: [PATCH] Remove unused old feed methods --- server/Database.js | 15 ----- server/models/Feed.js | 112 ----------------------------------- server/models/FeedEpisode.js | 33 ----------- 3 files changed, 160 deletions(-) diff --git a/server/Database.js b/server/Database.js index 95e13c6b..afb09dae 100644 --- a/server/Database.js +++ b/server/Database.js @@ -444,21 +444,6 @@ class Database { return updated } - async createFeed(oldFeed) { - if (!this.sequelize) return false - await this.models.feed.fullCreateFromOld(oldFeed) - } - - updateFeed(oldFeed) { - if (!this.sequelize) return false - return this.models.feed.fullUpdateFromOld(oldFeed) - } - - async removeFeed(feedId) { - if (!this.sequelize) return false - await this.models.feed.removeById(feedId) - } - async createBulkBookAuthors(bookAuthors) { if (!this.sequelize) return false await this.models.bookAuthor.bulkCreate(bookAuthors) diff --git a/server/models/Feed.js b/server/models/Feed.js index f6ee4e3c..5aaa4856 100644 --- a/server/models/Feed.js +++ b/server/models/Feed.js @@ -1,7 +1,6 @@ const Path = require('path') const { DataTypes, Model } = require('sequelize') const oldFeed = require('../objects/Feed') -const areEquivalent = require('../utils/areEquivalent') const Logger = require('../Logger') const RSS = require('../libs/rss') @@ -143,20 +142,6 @@ class Feed extends Model { ) } - /** - * Find all library item ids that have an open feed (used in library filter) - * @returns {Promise} array of library item ids - */ - static async findAllLibraryItemIds() { - const feeds = await this.findAll({ - attributes: ['entityId'], - where: { - entityType: 'libraryItem' - } - }) - return feeds.map((f) => f.entityId).filter((f) => f) || [] - } - /** * Find feed where and return oldFeed * @param {Object} where sequelize where object @@ -174,103 +159,6 @@ class Feed extends Model { return this.getOldFeed(feedExpanded) } - static async fullCreateFromOld(oldFeed) { - const feedObj = this.getFromOld(oldFeed) - const newFeed = await this.create(feedObj) - - if (oldFeed.episodes?.length) { - for (const oldFeedEpisode of oldFeed.episodes) { - const feedEpisode = this.sequelize.models.feedEpisode.getFromOld(oldFeedEpisode) - feedEpisode.feedId = newFeed.id - await this.sequelize.models.feedEpisode.create(feedEpisode) - } - } - } - - static async fullUpdateFromOld(oldFeed) { - const oldFeedEpisodes = oldFeed.episodes || [] - const feedObj = this.getFromOld(oldFeed) - - const existingFeed = await this.findByPk(feedObj.id, { - include: this.sequelize.models.feedEpisode - }) - if (!existingFeed) return false - - let hasUpdates = false - - // Remove and update existing feed episodes - for (const feedEpisode of existingFeed.feedEpisodes) { - const oldFeedEpisode = oldFeedEpisodes.find((ep) => ep.id === feedEpisode.id) - // Episode removed - if (!oldFeedEpisode) { - feedEpisode.destroy() - } else { - let episodeHasUpdates = false - const oldFeedEpisodeCleaned = this.sequelize.models.feedEpisode.getFromOld(oldFeedEpisode) - for (const key in oldFeedEpisodeCleaned) { - if (!areEquivalent(oldFeedEpisodeCleaned[key], feedEpisode[key])) { - episodeHasUpdates = true - } - } - if (episodeHasUpdates) { - await feedEpisode.update(oldFeedEpisodeCleaned) - hasUpdates = true - } - } - } - - // Add new feed episodes - for (const episode of oldFeedEpisodes) { - if (!existingFeed.feedEpisodes.some((fe) => fe.id === episode.id)) { - await this.sequelize.models.feedEpisode.createFromOld(feedObj.id, episode) - hasUpdates = true - } - } - - let feedHasUpdates = false - for (const key in feedObj) { - let existingValue = existingFeed[key] - if (existingValue instanceof Date) existingValue = existingValue.valueOf() - - if (!areEquivalent(existingValue, feedObj[key])) { - feedHasUpdates = true - } - } - - if (feedHasUpdates) { - await existingFeed.update(feedObj) - hasUpdates = true - } - - return hasUpdates - } - - static getFromOld(oldFeed) { - const oldFeedMeta = oldFeed.meta || {} - return { - id: oldFeed.id, - slug: oldFeed.slug, - entityType: oldFeed.entityType, - entityId: oldFeed.entityId, - entityUpdatedAt: oldFeed.entityUpdatedAt, - serverAddress: oldFeed.serverAddress, - feedURL: oldFeed.feedUrl, - coverPath: oldFeed.coverPath || null, - imageURL: oldFeedMeta.imageUrl, - siteURL: oldFeedMeta.link, - title: oldFeedMeta.title, - description: oldFeedMeta.description, - author: oldFeedMeta.author, - podcastType: oldFeedMeta.type || null, - language: oldFeedMeta.language || null, - ownerName: oldFeedMeta.ownerName || null, - ownerEmail: oldFeedMeta.ownerEmail || null, - explicit: !!oldFeedMeta.explicit, - preventIndexing: !!oldFeedMeta.preventIndexing, - userId: oldFeed.userId - } - } - /** * * @param {string} userId diff --git a/server/models/FeedEpisode.js b/server/models/FeedEpisode.js index b14f1b7b..31b26800 100644 --- a/server/models/FeedEpisode.js +++ b/server/models/FeedEpisode.js @@ -47,39 +47,6 @@ class FeedEpisode extends Model { this.updatedAt } - /** - * Create feed episode from old model - * - * @param {string} feedId - * @param {Object} oldFeedEpisode - * @returns {Promise} - */ - static createFromOld(feedId, oldFeedEpisode) { - const newEpisode = this.getFromOld(oldFeedEpisode) - newEpisode.feedId = feedId - return this.create(newEpisode) - } - - static getFromOld(oldFeedEpisode) { - return { - id: oldFeedEpisode.id, - title: oldFeedEpisode.title, - author: oldFeedEpisode.author, - description: oldFeedEpisode.description, - siteURL: oldFeedEpisode.link, - enclosureURL: oldFeedEpisode.enclosure?.url || null, - enclosureType: oldFeedEpisode.enclosure?.type || null, - enclosureSize: oldFeedEpisode.enclosure?.size || null, - pubDate: oldFeedEpisode.pubDate, - season: oldFeedEpisode.season || null, - episode: oldFeedEpisode.episode || null, - episodeType: oldFeedEpisode.episodeType || null, - duration: oldFeedEpisode.duration, - filePath: oldFeedEpisode.fullPath, - explicit: !!oldFeedEpisode.explicit - } - } - /** * * @param {import('./LibraryItem').LibraryItemExpanded} libraryItemExpanded