Skip to content

Commit

Permalink
Merge pull request #1700 from loujine/MBS-11117-long_discids_report
Browse files Browse the repository at this point in the history
MBS-11117: Create report for too long discIDs
  • Loading branch information
reosarevok committed Oct 12, 2020
2 parents 8e70d08 + 686e18a commit 2cf4be1
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 4 deletions.
42 changes: 42 additions & 0 deletions lib/MusicBrainz/Server/Report/CDTOCDubiousLength.pm
@@ -0,0 +1,42 @@
package MusicBrainz::Server::Report::CDTOCDubiousLength;
use Moose;

with 'MusicBrainz::Server::Report::CDTOCReport';

sub table { 'cd_toc_dubious_length' }
sub component_name { 'CDTocDubiousLength' }

sub query {
q{
SELECT
cdtoc.id AS cdtoc_id,
medium_format.name AS format,
cdtoc.leadout_offset / 75 AS length, -- seconds
row_number() OVER (
ORDER BY medium_format.name, cdtoc.leadout_offset DESC)
FROM
cdtoc
JOIN medium_cdtoc ON medium_cdtoc.cdtoc = cdtoc.id
JOIN medium ON medium_cdtoc.medium = medium.id
JOIN medium_format ON medium.format = medium_format.id
WHERE
leadout_offset > 75 * 60 * 100 -- cutoff 100 minutes
ORDER BY
medium_format.name,
cdtoc.leadout_offset DESC
}
}

__PACKAGE__->meta->make_immutable;
no Moose;
1;

=head1 COPYRIGHT AND LICENSE
Copyright (C) 2020 Jerome Roy
This file is part of MusicBrainz, the open internet music database,
and is licensed under the GPL version 2, or (at your option) any
later version: http://www.gnu.org/licenses/gpl-2.0.txt
=cut
34 changes: 34 additions & 0 deletions lib/MusicBrainz/Server/Report/CDTOCReport.pm
@@ -0,0 +1,34 @@
package MusicBrainz::Server::Report::CDTOCReport;
use Moose::Role;

with 'MusicBrainz::Server::Report::QueryReport';

around inflate_rows => sub {
my $orig = shift;
my $self = shift;

my $items = $self->$orig(@_);

my $cdtocs = $self->c->model('CDTOC')->get_by_ids(
map { $_->{cdtoc_id} } @$items
);

return [
map +{
%$_,
cdtoc => $cdtocs->{ $_->{cdtoc_id} },
}, @$items
];
};

1;

=head1 COPYRIGHT
Copyright (C) 2020 Jerome Roy
This file is part of MusicBrainz, the open internet music database,
and is licensed under the GPL version 2, or (at your option) any
later version: http://www.gnu.org/licenses/gpl-2.0.txt
=cut
2 changes: 2 additions & 0 deletions lib/MusicBrainz/Server/ReportFactory.pm
Expand Up @@ -22,6 +22,7 @@ use MusicBrainz::Server::PagedReport;
BadAmazonURLs
CatNoLooksLikeASIN
CatNoLooksLikeLabelCode
CDTOCDubiousLength
CollaborationRelationships
CoverArtRelationships
DeprecatedRelationshipArtists
Expand Down Expand Up @@ -106,6 +107,7 @@ use MusicBrainz::Server::Report::ArtistsWithNoSubscribers;
use MusicBrainz::Server::Report::BadAmazonURLs;
use MusicBrainz::Server::Report::CatNoLooksLikeASIN;
use MusicBrainz::Server::Report::CatNoLooksLikeLabelCode;
use MusicBrainz::Server::Report::CDTOCDubiousLength;
use MusicBrainz::Server::Report::CollaborationRelationships;
use MusicBrainz::Server::Report::CoverArtRelationships;
use MusicBrainz::Server::Report::DeprecatedRelationshipArtists;
Expand Down
49 changes: 49 additions & 0 deletions root/report/CDTocDubiousLength.js
@@ -0,0 +1,49 @@
/*
* @flow strict-local
* Copyright (C) 2020 Jerome Roy
*
* This file is part of MusicBrainz, the open internet music database,
* and is licensed under the GPL version 2, or (at your option) any
* later version: http://www.gnu.org/licenses/gpl-2.0.txt
*/

import * as React from 'react';

import Layout from '../layout';
import formatUserDate from '../utility/formatUserDate';

import CDTocList from './components/CDTocList';
import type {ReportDataT, ReportCDTocT} from './types';

const CDTocDubiousLength = ({
$c,
generated,
items,
pager,
}: ReportDataT<ReportCDTocT>): React.Element<typeof Layout> => (
<Layout $c={$c} fullWidth title={l('Disc IDs with dubious duration')}>
<h1>{l('Disc IDs with dubious duration')}</h1>

<ul>
<li>
{l(`This report shows disc IDs indicating a total duration much longer
than what a standard CD allows (at least 100 minutes). This usually
means a disc ID was created for the wrong format (SACD) or with a
buggy tool. These disc IDs can safely be removed.`)}
</li>
<li>
{texp.l('Total releases found: {count}',
{count: pager.total_entries})}
</li>
<li>
{texp.l('Generated on {date}',
{date: formatUserDate($c, generated)})}
</li>
</ul>

<CDTocList items={items} pager={pager} />

</Layout>
);

export default CDTocDubiousLength;
10 changes: 10 additions & 0 deletions root/report/ReportsIndex.js
Expand Up @@ -570,6 +570,16 @@ const ReportsIndex = ({$c}: Props): React.Element<typeof Layout> => (
</a>
</li>
</ul>

<h2>{l('Disc IDs')}</h2>

<ul>
<li>
<a href="/report/CDTOCDubiousLength">
{l('Disc IDs with dubious duration')}
</a>
</li>
</ul>
</div>
</Layout>
);
Expand Down
74 changes: 74 additions & 0 deletions root/report/components/CDTocList.js
@@ -0,0 +1,74 @@
/*
* @flow strict-local
* Copyright (C) 2020 Jerome Roy
*
* This file is part of MusicBrainz, the open internet music database,
* and is licensed under the GPL version 2, or (at your option) any
* later version: http://www.gnu.org/licenses/gpl-2.0.txt
*/

import * as React from 'react';

import PaginatedResults from '../../components/PaginatedResults';
import loopParity from '../../utility/loopParity';
import type {ReportCDTocT} from '../types';
import CDTocLink
from '../../static/scripts/common/components/CDTocLink';
import formatTrackLength
from '../../static/scripts/common/utility/formatTrackLength';

type Props = {
+items: $ReadOnlyArray<ReportCDTocT>,
+pager: PagerT,
};

const CDTocList = ({
items,
pager,
}: Props): React.Element<typeof PaginatedResults> => {
const colSpan = 3;

return (
<PaginatedResults pager={pager}>
<table className="tbl">
<thead>
<tr>
<th>{l('Disc ID')}</th>
<th>{l('Format')}</th>
<th>{l('Length')}</th>
</tr>
</thead>
<tbody>
{items.map((item, index) => {
return (
<tr className={loopParity(index)} key={item.cdtoc_id}>
{item.cdtoc ? (
<>
<td>
<CDTocLink
cdToc={item.cdtoc}
content={item.cdtoc.discid}
/>
</td>
<td>
{item.format}
</td>
<td>
{formatTrackLength(1000 * item.length)}
</td>
</>
) : (
<td colSpan={colSpan}>
{l('This Disc ID no longer exists.')}
</td>
)}
</tr>
);
})}
</tbody>
</table>
</PaginatedResults>
);
};

export default CDTocList;
8 changes: 8 additions & 0 deletions root/report/types.js
Expand Up @@ -39,6 +39,14 @@ export type ReportArtistUrlT = {
+url: UrlT,
};

export type ReportCDTocT = {
+cdtoc: ?CDTocT,
+cdtoc_id: number,
+format: string,
+length: number,
+row_number: number,
};

export type ReportCollaborationT = {
+artist0: ?ArtistT,
+artist1: ?ArtistT,
Expand Down
1 change: 1 addition & 0 deletions root/server/components.js
Expand Up @@ -140,6 +140,7 @@ module.exports = {
'report/BadAmazonUrls': require('../report/BadAmazonUrls'),
'report/CatNoLooksLikeAsin': require('../report/CatNoLooksLikeAsin'),
'report/CatNoLooksLikeLabelCode': require('../report/CatNoLooksLikeLabelCode'),
'report/CDTocDubiousLength': require('../report/CDTocDubiousLength'),
'report/CollaborationRelationships': require('../report/CollaborationRelationships'),
'report/CoverArtRelationships': require('../report/CoverArtRelationships'),
'report/DeprecatedRelationshipArtists': require('../report/DeprecatedRelationshipArtists'),
Expand Down
5 changes: 1 addition & 4 deletions root/types.js
Expand Up @@ -749,12 +749,9 @@ declare type MediumFormatT = {
};

declare type MediumT = $ReadOnly<{
/*
* TODO: still missing +cdtocs: $ReadOnlyArray<MediumCdTocT>
* (MediumCdTocT is not defined yet)
*/
...EntityRoleT<'track'>,
...LastUpdateRoleT,
+cdtocs: $ReadOnlyArray<MediumCDTocT>,
+editsPending: boolean,
+format: MediumFormatT | null,
+format_id: number,
Expand Down

0 comments on commit 2cf4be1

Please sign in to comment.