Improved 'new' sorting.

This commit is contained in:
DebaucheryLibrarian 2020-08-19 21:48:55 +02:00
parent e896d52968
commit fd4477bc50
4 changed files with 30 additions and 15 deletions

View File

@ -228,6 +228,15 @@ export default {
height: 1rem; height: 1rem;
} }
.content-inner {
display: flex;
flex-direction: column;
}
.releases {
flex-grow: 1;
}
.name { .name {
color: var(--text-light); color: var(--text-light);
display: flex; display: flex;

View File

@ -2,23 +2,23 @@ import dayjs from 'dayjs';
const dateRanges = { const dateRanges = {
latest: () => ({ latest: () => ({
after: '1900-01-01', after: '1900-01-01 00:00:00',
before: dayjs(new Date()).add(1, 'day').format('YYYY-MM-DD'), before: dayjs().format('YYYY-MM-DD HH:mm:ss'),
orderBy: 'DATE_DESC', orderBy: 'DATE_DESC',
}), }),
upcoming: () => ({ upcoming: () => ({
after: dayjs(new Date()).format('YYYY-MM-DD'), after: dayjs().format('YYYY-MM-DD HH:mm:ss'),
before: '2100-01-01', before: '2100-01-01 00:00:00',
orderBy: 'DATE_ASC', orderBy: 'DATE_ASC',
}), }),
new: () => ({ new: () => ({
after: '1900-01-01', after: '1900-01-01 00:00:00',
before: '2100-01-01', before: '2100-01-01 00:00:00',
orderBy: 'CREATED_AT_DESC', orderBy: ['CREATED_AT_DESC', 'DATE_ASC'],
}), }),
all: () => ({ all: () => ({
after: '1900-01-01', after: '1900-01-01 00:00:00',
before: '2100-01-01', before: '2100-01-01 00:00:00',
orderBy: 'DATE_DESC', orderBy: 'DATE_DESC',
}), }),
}; };

View File

@ -7,13 +7,15 @@ function initReleasesActions(store, _router) {
async function fetchReleases({ _commit }, { limit = 10, pageNumber = 1, range = 'latest' }) { async function fetchReleases({ _commit }, { limit = 10, pageNumber = 1, range = 'latest' }) {
const { before, after, orderBy } = getDateRange(range); const { before, after, orderBy } = getDateRange(range);
console.log(after, before, orderBy);
const { connection: { releases, totalCount } } = await graphql(` const { connection: { releases, totalCount } } = await graphql(`
query Releases( query Releases(
$limit:Int = 1000, $limit:Int = 1000,
$offset:Int = 0, $offset:Int = 0,
$after:Datetime = "1900-01-01", $after:Datetime = "1900-01-01 00:00:00",
$before:Datetime = "2100-01-01", $before:Datetime = "2100-01-01 00:00:00",
$orderBy:[ReleasesOrderBy!], $orderBy: [ReleasesOrderBy!],
$exclude: [String!] $exclude: [String!]
) { ) {
${releasesFragment} ${releasesFragment}

View File

@ -37,7 +37,7 @@ async function filterUniqueReleases(latestReleases, accReleases) {
return uniqueReleases; return uniqueReleases;
} }
function needNextPage(uniqueReleases, pageAccReleases) { function needNextPage(uniqueReleases, pageAccReleases, hasDates) {
if (uniqueReleases.length === 0) { if (uniqueReleases.length === 0) {
return false; return false;
} }
@ -47,7 +47,7 @@ function needNextPage(uniqueReleases, pageAccReleases) {
return true; return true;
} }
if (uniqueReleases.every(release => !!release.date)) { if (hasDates) {
const oldestReleaseOnPage = uniqueReleases const oldestReleaseOnPage = uniqueReleases
.sort((releaseA, releaseB) => releaseB.date - releaseA.date) .sort((releaseA, releaseB) => releaseB.date - releaseA.date)
.slice(-1)[0]; .slice(-1)[0];
@ -79,6 +79,10 @@ async function scrapeReleases(scraper, entity, preData, upcoming = false) {
entity: release.entity || entity, // allow override entity: release.entity || entity, // allow override
})); // attach entity the release is assigned to when stored })); // attach entity the release is assigned to when stored
const hasDates = latestReleasesWithEntity.every(release => !!release.date);
console.log(hasDates);
const uniqueReleases = argv.redownload const uniqueReleases = argv.redownload
? latestReleasesWithEntity ? latestReleasesWithEntity
: await filterUniqueReleases(latestReleasesWithEntity, accReleases); : await filterUniqueReleases(latestReleasesWithEntity, accReleases);
@ -87,7 +91,7 @@ async function scrapeReleases(scraper, entity, preData, upcoming = false) {
logger.verbose(`Scraped '${entity.name}' (${entity.parent?.name}) ${upcoming ? 'upcoming' : 'latest'} page ${page}, found ${uniqueReleases.length} unique updates`); logger.verbose(`Scraped '${entity.name}' (${entity.parent?.name}) ${upcoming ? 'upcoming' : 'latest'} page ${page}, found ${uniqueReleases.length} unique updates`);
if (needNextPage(uniqueReleases, pageAccReleases)) { if (needNextPage(uniqueReleases, pageAccReleases, hasDates)) {
return scrapePage(page + 1, pageAccReleases); return scrapePage(page + 1, pageAccReleases);
} }