Refactoring client to reflect database changes.

This commit is contained in:
ThePendulum 2019-12-19 04:42:50 +01:00
parent 31aee71edb
commit 1c43884102
9 changed files with 114 additions and 78 deletions

View File

@ -75,6 +75,8 @@ async function mounted() {
], ],
}); });
console.log(tags);
this.tags = tags.reduce((acc, tag) => { this.tags = tags.reduce((acc, tag) => {
if (acc[tag.group.slug]) { if (acc[tag.group.slug]) {
return { ...acc, [tag.group.slug]: [...acc[tag.group.slug], tag] }; return { ...acc, [tag.group.slug]: [...acc[tag.group.slug], tag] };

View File

@ -1,12 +1,13 @@
function curateActor(actor) { function curateActor(actor) {
const curatedActor = { const curatedActor = {
...actor, ...actor,
avatar: actor.avatar[0],
origin: actor.originCountry && { origin: actor.originCountry && {
country: actor.originCountry, country: actor.originCountry,
}, },
}; };
if (actor.avatar) curatedActor.avatar = actor.avatar.media;
return curatedActor; return curatedActor;
} }
@ -14,17 +15,31 @@ function curateRelease(release) {
const curatedRelease = { const curatedRelease = {
...release, ...release,
actors: release.actors.map(({ actor }) => curateActor(actor)), actors: release.actors.map(({ actor }) => curateActor(actor)),
poster: release.poster[0], poster: release.poster && release.poster.media,
network: release.site.network,
tags: release.tags.map(({ tag }) => tag), tags: release.tags.map(({ tag }) => tag),
network: release.site.network,
}; };
if (release.trailer) [curatedRelease.trailer] = release.trailer; if (release.photos) curatedRelease.photos = release.photos.map(({ media }) => media);
if (release.trailer) [curatedRelease.trailer] = release.trailer.media;
return curatedRelease; return curatedRelease;
} }
function curateTag(tag) {
const curatedTag = {
...tag,
};
if (tag.releases) curatedTag.releases = tag.releases.map(({ release }) => curateRelease(release));
if (tag.photos) curatedTag.photos = tag.photos.map(({ media }) => media);
if (tag.poster) curatedTag.poster = tag.poster.media;
return curatedTag;
}
export { export {
curateActor, curateActor,
curateRelease, curateRelease,
curateTag,
}; };

View File

@ -14,8 +14,8 @@ const siteFragment = `
`; `;
const releaseActorsFragment = ` const releaseActorsFragment = `
actors: releasesActors(orderBy: GENDER_ASC) { actors: releasesActorsSortables(orderBy: GENDER_ASC) {
actor: releaseActor { actor {
id id
name name
slug slug
@ -26,16 +26,18 @@ const releaseActorsFragment = `
name name
alias alias
} }
avatar: actorsMediasByTargetId(condition: { role: "avatar" }) { avatar: actorsAvatarByActorId {
media {
thumbnail thumbnail
} }
} }
} }
}
`; `;
const releaseTagsFragment = ` const releaseTagsFragment = `
tags: releasesTagsByTargetId { tags: releasesTags {
tag: releaseTag { tag {
name name
priority priority
slug slug
@ -45,29 +47,35 @@ const releaseTagsFragment = `
`; `;
const releasePosterFragment = ` const releasePosterFragment = `
poster: releasesMediasByTargetId(condition: { role: "poster" }) { poster: releasesPosterByReleaseId {
media {
index index
path path
thumbnail thumbnail
comment comment
} }
}
`; `;
const releasePhotosFragment = ` const releasePhotosFragment = `
photos: releasesMediasByTargetId(condition: { role: "photo" }) { photos: releasesPhotos {
media {
index index
path path
thumbnail thumbnail
comment comment
} }
}
`; `;
const releaseTrailerFragment = ` const releaseTrailerFragment = `
trailer: releasesMediasByTargetId(condition: { role: "trailer" }) { trailer: releasesTrailerByReleaseId {
media {
index index
path path
thumbnail thumbnail
} }
}
`; `;
const releasesFragment = ` const releasesFragment = `

View File

@ -5,18 +5,7 @@ import {
releaseTagsFragment, releaseTagsFragment,
siteFragment, siteFragment,
} from '../fragments'; } from '../fragments';
import { curateRelease } from '../curate'; import { curateTag } from '../curate';
function curateTag(tag) {
const curatedTag = {
...tag,
};
if (tag.releases) curatedTag.releases = tag.releases.map(({ tagRelease }) => curateRelease(tagRelease));
if (tag.poster) [curatedTag.poster] = tag.poster;
return curatedTag;
}
function initTagsActions(store, _router) { function initTagsActions(store, _router) {
async function fetchTagBySlug(tagSlug) { async function fetchTagBySlug(tagSlug) {
@ -31,20 +20,24 @@ function initTagsActions(store, _router) {
name name
slug slug
} }
poster: tagsMediasByTargetId(condition: { role: "poster" }) { poster: tagsPosterByTagId {
media {
id id
thumbnail thumbnail
path path
comment comment
} }
photos: tagsMediasByTargetId(condition: { role: "photo" }) { }
photos: tagsPhotos {
media {
id id
thumbnail thumbnail
path path
comment comment
} }
}
releases: releasesTags { releases: releasesTags {
tagRelease { release {
id id
title title
date date
@ -82,9 +75,11 @@ function initTagsActions(store, _router) {
id id
name name
slug slug
poster: tagsMediasByTargetId(condition: { role: "poster" }) { poster: tagsPosterByTagId {
media {
thumbnail thumbnail
} }
}
group { group {
name name
slug slug

View File

@ -378,6 +378,19 @@ exports.up = knex => Promise.resolve()
table.unique('release_id'); table.unique('release_id');
})) }))
.then(() => knex.schema.createTable('releases_trailers', (table) => {
table.integer('release_id', 16)
.notNullable()
.references('id')
.inTable('releases');
table.integer('media_id', 16)
.notNullable()
.references('id')
.inTable('media');
table.unique('release_id');
}))
.then(() => knex.schema.createTable('releases_photos', (table) => { .then(() => knex.schema.createTable('releases_photos', (table) => {
table.integer('release_id', 16) table.integer('release_id', 16)
.notNullable() .notNullable()
@ -405,27 +418,34 @@ exports.up = knex => Promise.resolve()
table.unique(['tag_id', 'release_id']); table.unique(['tag_id', 'release_id']);
})) }))
.then(() => knex.raw(` .then(() => knex.raw(`
CREATE VIEW releases_actors_sortable AS
SELECT releases_actors.*, actors.gender, actors.name, actors.birthdate FROM releases_actors
JOIN actors ON releases_actors.actor_id = actors.id;
COMMENT ON VIEW releases_actors_sortable IS E'@foreignKey (release_id) references releases (id)\n@foreignKey (actor_id) references actors (id)';
/* allow conversion resolver to be added for height and weight */ /* allow conversion resolver to be added for height and weight */
COMMENT ON COLUMN actors.height IS E'@omit read,update,create,delete,all,many'; COMMENT ON COLUMN actors.height IS E'@omit read,update,create,delete,all,many';
COMMENT ON COLUMN actors.weight IS E'@omit read,update,create,delete,all,many'; COMMENT ON COLUMN actors.weight IS E'@omit read,update,create,delete,all,many';
/* CREATE FUNCTION releases_by_tag_slugs(slugs text[]) RETURNS setof releases AS $$
create function releases_by_tag_slugs(slugs text[]) returns setof releases as $$ SELECT DISTINCT ON (releases.id) releases.* FROM releases
select distinct on (releases.id) releases.* from releases JOIN releases_tags ON (releases_tags.release_id = releases.id)
join releases_tags on (releases_tags.release_id = releases.id) JOIN tags ON (releases_tags.tag_id = tags.id)
join tags on (releases_tags.tag_id = tags.id) WHERE tags.slug = ANY($1);
where tags.slug = ANY($1); $$ LANGUAGE sql STABLE
$$ language sql stable
*/
`)); `));
exports.down = knex => knex.raw(` exports.down = knex => knex.raw(`
DROP FUNCTION IF EXISTS releases_by_tag_slugs; DROP FUNCTION IF EXISTS releases_by_tag_slugs;
DROP VIEW IF EXISTS releases_actors_view;
DROP TABLE IF EXISTS releases_actors CASCADE; DROP TABLE IF EXISTS releases_actors CASCADE;
DROP TABLE IF EXISTS releases_directors CASCADE; DROP TABLE IF EXISTS releases_directors CASCADE;
DROP TABLE IF EXISTS releases_posters CASCADE; DROP TABLE IF EXISTS releases_posters CASCADE;
DROP TABLE IF EXISTS releases_photos CASCADE; DROP TABLE IF EXISTS releases_photos CASCADE;
DROP TABLE IF EXISTS releases_trailers CASCADE;
DROP TABLE IF EXISTS releases_tags CASCADE; DROP TABLE IF EXISTS releases_tags CASCADE;
DROP TABLE IF EXISTS actors_avatars CASCADE; DROP TABLE IF EXISTS actors_avatars CASCADE;
DROP TABLE IF EXISTS actors_photos CASCADE; DROP TABLE IF EXISTS actors_photos CASCADE;

View File

@ -1544,7 +1544,7 @@ function getTagAliases(tagsMap) {
exports.seed = knex => Promise.resolve() exports.seed = knex => Promise.resolve()
.then(async () => upsert('tags_groups', groups, 'slug', knex)) .then(async () => upsert('tags_groups', groups, 'slug', knex))
.then(async () => { .then(async () => {
const groupEntries = knex('tags').select('*'); const groupEntries = await knex('tags_groups').select('*');
const groupsMap = groupEntries.reduce((acc, { id, slug }) => ({ ...acc, [slug]: id }), {}); const groupsMap = groupEntries.reduce((acc, { id, slug }) => ({ ...acc, [slug]: id }), {});
const tags = getTags(groupsMap); const tags = getTags(groupsMap);

View File

@ -11,6 +11,11 @@ const tagPosters = [
tagSlug: 'anal', tagSlug: 'anal',
comment: '', comment: '',
}, },
{
path: 'tags/da-tp/0.jpeg',
tagSlug: 'da-tp',
comment: 'Natasha Teen in LegalPorno SZ2164',
},
{ {
path: 'tags/double-penetration/poster.jpeg', path: 'tags/double-penetration/poster.jpeg',
tagSlug: 'double-penetration', tagSlug: 'double-penetration',
@ -26,6 +31,11 @@ const tagPosters = [
tagSlug: 'double-vaginal', tagSlug: 'double-vaginal',
comment: '', comment: '',
}, },
{
path: 'tags/dv-tp/poster.jpeg',
tagSlug: 'dv-tp',
comment: 'Juelz Ventura in "Gangbanged 5" for Elegant Angel',
},
{ {
path: 'tags/tattoo/poster.jpeg', path: 'tags/tattoo/poster.jpeg',
tagSlug: 'tattoo', tagSlug: 'tattoo',
@ -141,11 +151,6 @@ const tagPhotos = [
tagSlug: 'airtight', tagSlug: 'airtight',
comment: 'Sheena Shaw in "Ass Worship 14" for Jules Jordan', comment: 'Sheena Shaw in "Ass Worship 14" for Jules Jordan',
}, },
{
path: 'tags/da-tp/0.jpeg',
tagSlug: 'da-tp',
comment: 'Natasha Teen in LegalPorno SZ2164',
},
{ {
path: 'tags/da-tp/3.jpeg', path: 'tags/da-tp/3.jpeg',
tagSlug: 'da-tp', tagSlug: 'da-tp',
@ -166,11 +171,6 @@ const tagPhotos = [
tagSlug: 'da-tp', tagSlug: 'da-tp',
comment: 'Ninel Mojado aka Mira Cuckold in GIO063 for LegalPorno', comment: 'Ninel Mojado aka Mira Cuckold in GIO063 for LegalPorno',
}, },
{
path: 'tags/dv-tp/poster.jpeg',
tagSlug: 'dv-tp',
comment: 'Juelz Ventura in "Gangbanged 5" for Elegant Angel',
},
{ {
path: 'tags/dv-tp/0.jpeg', path: 'tags/dv-tp/0.jpeg',
tagSlug: 'dv-tp', tagSlug: 'dv-tp',

View File

@ -399,7 +399,7 @@ async function scrapeBasicActors() {
async function associateActors(mappedActors, releases) { async function associateActors(mappedActors, releases) {
const [existingActorEntries, existingAssociationEntries] = await Promise.all([ const [existingActorEntries, existingAssociationEntries] = await Promise.all([
knex('actors').whereIn('name', Object.keys(mappedActors)), knex('actors').whereIn('name', Object.keys(mappedActors)),
knex('actors_associated').whereIn('release_id', releases.map(release => release.id)), knex('releases_actors').whereIn('release_id', releases.map(release => release.id)),
]); ]);
const associations = await Promise.map(Object.entries(mappedActors), async ([actorName, releaseIds]) => { const associations = await Promise.map(Object.entries(mappedActors), async ([actorName, releaseIds]) => {
@ -418,7 +418,7 @@ async function associateActors(mappedActors, releases) {
}); });
await Promise.all([ await Promise.all([
knex('actors_associated').insert(associations.flat()), knex('releases_actors').insert(associations.flat()),
scrapeBasicActors(), scrapeBasicActors(),
]); ]);
} }

View File

@ -66,20 +66,16 @@ async function associateTags(release, releaseId) {
? await matchTags(release.tags) // scraper returned raw tags ? await matchTags(release.tags) // scraper returned raw tags
: release.tags; // tags already matched by (outdated) scraper : release.tags; // tags already matched by (outdated) scraper
const associationEntries = await knex('tags_associated') const associationEntries = await knex('releases_tags')
.where({ .where('release_id', releaseId)
domain: 'releases',
target_id: releaseId,
})
.whereIn('tag_id', tags); .whereIn('tag_id', tags);
const existingAssociations = new Set(associationEntries.map(association => association.tag_id)); const existingAssociations = new Set(associationEntries.map(association => association.tag_id));
const newAssociations = tags.filter(tagId => !existingAssociations.has(tagId)); const newAssociations = tags.filter(tagId => !existingAssociations.has(tagId));
await knex('tags_associated').insert(newAssociations.map(tagId => ({ await knex('releases_tags').insert(newAssociations.map(tagId => ({
tag_id: tagId, tag_id: tagId,
domain: 'releases', release_id: releaseId,
target_id: releaseId,
}))); })));
} }