From a2331bc91358f69afb9895d3984e419bedc1e752 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Sat, 1 Jul 2023 22:24:21 +0200 Subject: [PATCH] Added prefer option for entity resolution. Merged migrations. --- migrations/20190325001339_releases.js | 2 ++ .../20230629052143_actor_orientation.js | 19 ------------------- src/argv.js | 6 ++++++ src/entities.js | 6 +++--- 4 files changed, 11 insertions(+), 22 deletions(-) delete mode 100644 migrations/20230629052143_actor_orientation.js diff --git a/migrations/20190325001339_releases.js b/migrations/20190325001339_releases.js index e806923f..74777efe 100755 --- a/migrations/20190325001339_releases.js +++ b/migrations/20190325001339_releases.js @@ -273,6 +273,7 @@ exports.up = (knex) => Promise.resolve() table.integer('age', 3); table.text('gender', 18); + table.text('orientation'); table.text('description'); table.text('birth_city'); @@ -346,6 +347,7 @@ exports.up = (knex) => Promise.resolve() table.text('real_name'); table.text('gender', 18); + table.text('orientation'); table.date('date_of_birth'); table.date('date_of_death'); diff --git a/migrations/20230629052143_actor_orientation.js b/migrations/20230629052143_actor_orientation.js deleted file mode 100644 index 8a2240ac..00000000 --- a/migrations/20230629052143_actor_orientation.js +++ /dev/null @@ -1,19 +0,0 @@ -exports.up = async (knex) => { - await knex.schema.alterTable('actors', (table) => { - table.text('orientation'); - }); - - await knex.schema.alterTable('actors_profiles', (table) => { - table.text('orientation'); - }); -}; - -exports.down = async (knex) => { - await knex.schema.alterTable('actors', (table) => { - table.dropColumn('orientation'); - }); - - await knex.schema.alterTable('actors_profiles', (table) => { - table.dropColumn('orientation'); - }); -}; diff --git a/src/argv.js b/src/argv.js index 4eea7970..873501ab 100755 --- a/src/argv.js +++ b/src/argv.js @@ -244,6 +244,12 @@ const { argv } = yargs type: 'string', default: process.env.NODE_ENV === 'development' ? 'silly' : 'info', }) + .option('prefer-entity', { + alias: 'prefer', + describe: 'Prefer network or channel when resolving entities with the same identifier.', + choices: ['channel', 'network'], + type: 'string', + }) .option('resolve-place', { describe: 'Call OSM Nominatim API for actor place of birth and residence. Raw value discarded if disabled.', type: 'boolean', diff --git a/src/entities.js b/src/entities.js index e1d252c7..9e06d8f0 100755 --- a/src/entities.js +++ b/src/entities.js @@ -199,7 +199,7 @@ async function fetchIncludedEntities() { return curatedNetworks; } -async function fetchEntitiesBySlug(entitySlugs, sort = 'asc') { +async function fetchEntitiesBySlug(entitySlugs, prefer = 'channel') { const entities = await knex.raw(` WITH RECURSIVE entity_tree as ( SELECT to_jsonb(entities) as entity, @@ -235,7 +235,7 @@ async function fetchEntitiesBySlug(entitySlugs, sort = 'asc') { `, { entitySlugs: entitySlugs.filter((slug) => !slug.includes('.')), entityHosts: entitySlugs.filter((slug) => slug.includes('.')).map((hostname) => `%${hostname}%`), - sort: knex.raw(sort), + sort: knex.raw(prefer === 'channel' ? 'asc' : 'desc'), }); // channel entity will overwrite network entity @@ -262,7 +262,7 @@ async function fetchReleaseEntities(baseReleases) { .filter(Boolean), )); - return fetchEntitiesBySlug(entitySlugs, 'desc'); + return fetchEntitiesBySlug(entitySlugs, argv.prefer || 'network'); } async function fetchEntity(entityId, type) {