diff --git a/server/models/Author.js b/server/models/Author.js index 65561e211..287b66976 100644 --- a/server/models/Author.js +++ b/server/models/Author.js @@ -111,17 +111,16 @@ class Author extends Model { * * @param {string} name * @param {string} libraryId - * @returns {Promise<{ author: Author, created: boolean }>} + * @returns {Promise} */ static async findOrCreateByNameAndLibrary(name, libraryId) { const author = await this.getByNameAndLibrary(name, libraryId) - if (author) return { author, created: false } - const newAuthor = await this.create({ + if (author) return author + return this.create({ name, lastFirst: this.getLastFirst(name), libraryId }) - return { author: newAuthor, created: true } } /** diff --git a/server/models/Book.js b/server/models/Book.js index d9f2ff132..96371f3a2 100644 --- a/server/models/Book.js +++ b/server/models/Book.js @@ -4,7 +4,6 @@ const { getTitlePrefixAtEnd, getTitleIgnorePrefix } = require('../utils') const parseNameString = require('../utils/parsers/parseNameString') const htmlSanitizer = require('../utils/htmlSanitizer') const libraryItemsBookFilters = require('../utils/queries/libraryItemsBookFilters') -const SocketAuthority = require('../SocketAuthority') /** * @typedef EBookFileObject @@ -471,23 +470,13 @@ class Book extends Model { for (const author of authorsRemoved) { await bookAuthorModel.removeByIds(author.id, this.id) - const numBooks = await bookAuthorModel.getCountForAuthor(author.id) - if (numBooks > 0) { - SocketAuthority.emitter('author_updated', author.toOldJSONExpanded(numBooks)) - } Logger.debug(`[Book] "${this.title}" Removed author "${author.name}"`) this.authors = this.authors.filter((au) => au.id !== author.id) } const authorsAdded = [] for (const authorName of newAuthorNames) { - const { author, created } = await authorModel.findOrCreateByNameAndLibrary(authorName, libraryId) + const author = await authorModel.findOrCreateByNameAndLibrary(authorName, libraryId) await bookAuthorModel.create({ bookId: this.id, authorId: author.id }) - if (created) { - SocketAuthority.emitter('author_added', author.toOldJSON()) - } else { - const numBooks = await bookAuthorModel.getCountForAuthor(author.id) - SocketAuthority.emitter('author_updated', author.toOldJSONExpanded(numBooks)) - } Logger.debug(`[Book] "${this.title}" Added author "${author.name}"`) this.authors.push(author) authorsAdded.push(author)