summaryrefslogtreecommitdiff
path: root/lib/VNDB/Handler
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2015-10-17 17:05:50 +0200
committerYorhel <git@yorhel.nl>2015-10-17 17:20:41 +0200
commit718f4d0258049aa92f229c08d5ec7204dae3ffa6 (patch)
treefc45906cbc145e85e7954671da10d7dbbab9dfbc /lib/VNDB/Handler
parenteed1eced579e022135f98f3f733ecab88e3b6b6e (diff)
SQL: Fix all browsing queries to use the new schema
This basically makes VNDB browsable again, but editing entries is still broken. I split off the get-old-revision functionality from the db*Get() methods into db*GetRev(). This split makes sense even with the old SQL schema: db*Get() had to special-case some joins/filters when fetching an older revision, and none of the other filters would work in that case. This split does cause some code duplication in that all db*GetRev() methods look very much alike, and that the columns they fetch is almost identical to the db*Get() methods. Not sure yet how to avoid the duplication elegantly. I didn't do a whole lot of query optimization yet (most issues require extra indices, I'll investigate later which indices will make a big difference), but I did fix some low hanging fruit whenever I encountered something. I don't think I've worsened anything, performance-wise.
Diffstat (limited to 'lib/VNDB/Handler')
-rw-r--r--lib/VNDB/Handler/Chars.pm11
-rw-r--r--lib/VNDB/Handler/Misc.pm4
-rw-r--r--lib/VNDB/Handler/Producers.pm13
-rw-r--r--lib/VNDB/Handler/Releases.pm11
-rw-r--r--lib/VNDB/Handler/Staff.pm12
-rw-r--r--lib/VNDB/Handler/VNEdit.pm2
-rw-r--r--lib/VNDB/Handler/VNPage.pm12
7 files changed, 34 insertions, 31 deletions
diff --git a/lib/VNDB/Handler/Chars.pm b/lib/VNDB/Handler/Chars.pm
index 7171d506..524b5a04 100644
--- a/lib/VNDB/Handler/Chars.pm
+++ b/lib/VNDB/Handler/Chars.pm
@@ -20,9 +20,10 @@ TUWF::register(
sub page {
my($self, $id, $rev) = @_;
- my $r = $self->dbCharGet(
+ my $method = $rev ? 'dbCharGetRev' : 'dbCharGet';
+ my $r = $self->$method(
id => $id,
- what => 'extended traits vns seiyuu'.($rev ? ' changes' : ''),
+ what => 'extended traits vns seiyuu',
$rev ? ( rev => $rev ) : ()
)->[0];
return $self->resNotFound if !$r->{id};
@@ -32,7 +33,7 @@ sub page {
return if $self->htmlHiddenMessage('c', $r);
if($rev) {
- my $prev = $rev && $rev > 1 && $self->dbCharGet(id => $id, rev => $rev-1, what => 'changes extended traits vns')->[0];
+ my $prev = $rev && $rev > 1 && $self->dbCharGetRev(id => $id, rev => $rev-1, what => 'extended traits vns')->[0];
$self->htmlRevision('c', $prev, $r,
[ name => diff => 1 ],
[ original => diff => 1 ],
@@ -265,9 +266,9 @@ sub edit {
$copy = $rev && $rev eq 'copy' || $copy && $copy eq 'copy';
$rev = undef if defined $rev && $rev !~ /^\d+$/;
- my $r = $id && $self->dbCharGet(id => $id, what => 'changes extended vns traits', $rev ? (rev => $rev) : ())->[0];
+ my $r = $id && $self->dbCharGetRev(id => $id, what => 'extended vns traits', $rev ? (rev => $rev) : ())->[0];
return $self->resNotFound if $id && !$r->{id};
- $rev = undef if !$r || $r->{cid} == $r->{latest};
+ $rev = undef if !$r || $r->{lastrev};
return $self->htmlDenied if !$self->authCan('edit')
|| $id && (($r->{locked} || $r->{hidden}) && !$self->authCan('dbmod'));
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm
index 8176d854..c32766b1 100644
--- a/lib/VNDB/Handler/Misc.pm
+++ b/lib/VNDB/Handler/Misc.pm
@@ -75,7 +75,7 @@ sub homepage {
for (@$changes) {
li;
lit mt '_home_recentchanges_item', $_->{type},
- sprintf('<a href="%s" title="%s">%s</a>', "/$_->{type}$_->{iid}.$_->{rev}",
+ sprintf('<a href="%s" title="%s">%s</a>', "/$_->{type}$_->{itemid}.$_->{rev}",
xml_escape($_->{ioriginal}||$_->{ititle}), xml_escape shorten $_->{ititle}, 33),
$_;
end;
@@ -214,7 +214,7 @@ sub history {
# get the edit history
my($list, $np) = $self->dbRevisionGet(
what => 'item user',
- $type && $type ne 'u' ? ( type => $type, iid => $id ) : (),
+ $type && $type ne 'u' ? ( type => $type, itemid => $id ) : (),
$type eq 'u' ? ( uid => $id ) : (),
$f->{t} ? ( type => $f->{t} eq 'a' ? [qw|v r p|] : $f->{t} ) : (),
page => $f->{p},
diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm
index 6369d4d1..628034c2 100644
--- a/lib/VNDB/Handler/Producers.pm
+++ b/lib/VNDB/Handler/Producers.pm
@@ -44,9 +44,10 @@ sub rg {
sub page {
my($self, $pid, $rev) = @_;
- my $p = $self->dbProducerGet(
+ my $method = $rev ? 'dbProducerGetRev' : 'dbProducerGet';
+ my $p = $self->$method(
id => $pid,
- what => 'extended relations'.($rev ? ' changes' : ''),
+ what => 'extended relations',
$rev ? ( rev => $rev ) : ()
)->[0];
return $self->resNotFound if !$p->{id};
@@ -56,7 +57,7 @@ sub page {
return if $self->htmlHiddenMessage('p', $p);
if($rev) {
- my $prev = $rev && $rev > 1 && $self->dbProducerGet(id => $pid, rev => $rev-1, what => 'changes extended relations')->[0];
+ my $prev = $rev && $rev > 1 && $self->dbProducerGetRev(id => $pid, rev => $rev-1, what => 'extended relations')->[0];
$self->htmlRevision('p', $prev, $p,
[ type => serialize => sub { mt "_ptype_$_[0]" } ],
[ name => diff => 1 ],
@@ -200,9 +201,9 @@ sub _releases {
sub edit {
my($self, $pid, $rev) = @_;
- my $p = $pid && $self->dbProducerGet(id => $pid, what => 'changes extended relations', $rev ? (rev => $rev) : ())->[0];
+ my $p = $pid && $self->dbProducerGetRev(id => $pid, what => 'extended relations', rev => $rev)->[0];
return $self->resNotFound if $pid && !$p->{id};
- $rev = undef if !$p || $p->{cid} == $p->{latest};
+ $rev = undef if !$p || $p->{lastrev};
return $self->htmlDenied if !$self->authCan('edit')
|| $pid && (($p->{locked} || $p->{hidden}) && !$self->authCan('dbmod'));
@@ -329,7 +330,7 @@ sub _updreverse {
# edit all related producers
for my $i (keys %upd) {
- my $r = $self->dbProducerGet(id => $i, what => 'relations')->[0];
+ my $r = $self->dbProducerGetRev(id => $i, what => 'relations')->[0];
my @newrel = map $_->{id} != $pid ? [ $_->{relation}, $_->{id} ] : (), @{$r->{relations}};
push @newrel, [ $upd{$i}, $pid ] if $upd{$i};
$self->dbItemEdit(p => $r->{cid},
diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm
index b06a62f3..1c97eced 100644
--- a/lib/VNDB/Handler/Releases.pm
+++ b/lib/VNDB/Handler/Releases.pm
@@ -20,9 +20,10 @@ TUWF::register(
sub page {
my($self, $rid, $rev) = @_;
- my $r = $self->dbReleaseGet(
+ my $method = $rev ? 'dbReleaseGetRev' : 'dbReleaseGet';
+ my $r = $self->$method(
id => $rid,
- what => 'vn extended producers platforms media'.($rev ? ' changes' : ''),
+ what => 'vn extended producers platforms media',
$rev ? (rev => $rev) : (),
)->[0];
return $self->resNotFound if !$r->{id};
@@ -32,7 +33,7 @@ sub page {
return if $self->htmlHiddenMessage('r', $r);
if($rev) {
- my $prev = $rev && $rev > 1 && $self->dbReleaseGet(
+ my $prev = $rev && $rev > 1 && $self->dbReleaseGetRev(
id => $rid, rev => $rev-1,
what => 'vn extended producers platforms media changes'
)->[0];
@@ -271,9 +272,9 @@ sub edit {
$rid = 0;
}
- my $r = $rid && $self->dbReleaseGet(id => $rid, what => 'vn extended producers platforms media changes', $rev ? (rev => $rev) : ())->[0];
+ my $r = $rid && $self->dbReleaseGetRev(id => $rid, what => 'vn extended producers platforms media', $rev ? (rev => $rev) : ())->[0];
return $self->resNotFound if $rid && !$r->{id};
- $rev = undef if !$r || $r->{cid} == $r->{latest};
+ $rev = undef if !$r || $r->{lastrev};
my $v = $vid && $self->dbVNGet(id => $vid)->[0];
return $self->resNotFound if $vid && !$v->{id};
diff --git a/lib/VNDB/Handler/Staff.pm b/lib/VNDB/Handler/Staff.pm
index 88e6d7c8..f2e855ba 100644
--- a/lib/VNDB/Handler/Staff.pm
+++ b/lib/VNDB/Handler/Staff.pm
@@ -19,9 +19,10 @@ TUWF::register(
sub page {
my($self, $id, $rev) = @_;
- my $s = $self->dbStaffGet(
+ my $method = $rev ? 'dbStaffGetRev' : 'dbStaffGet';
+ my $s = $self->$method(
id => $id,
- what => 'extended aliases roles'.($rev ? ' changes' : ''),
+ what => 'extended aliases roles',
$rev ? ( rev => $rev ) : ()
)->[0];
return $self->resNotFound if !$s->{id};
@@ -31,7 +32,7 @@ sub page {
return if $self->htmlHiddenMessage('s', $s);
if($rev) {
- my $prev = $rev && $rev > 1 && $self->dbStaffGet(id => $id, rev => $rev-1, what => 'changes extended aliases')->[0];
+ my $prev = $rev && $rev > 1 && $self->dbStaffGetRev(id => $id, rev => $rev-1, what => 'extended aliases')->[0];
$self->htmlRevision('s', $prev, $s,
[ name => diff => 1 ],
[ original => diff => 1 ],
@@ -179,9 +180,9 @@ sub _cast {
sub edit {
my($self, $sid, $rev) = @_;
- my $s = $sid && $self->dbStaffGet(id => $sid, what => 'changes extended aliases', $rev ? (rev => $rev) : ())->[0];
+ my $s = $sid && $self->dbStaffGetRev(id => $sid, what => 'extended aliases', $rev ? (rev => $rev) : ())->[0];
return $self->resNotFound if $sid && !$s->{id};
- $rev = undef if !$s || $s->{cid} == $s->{latest};
+ $rev = undef if !$s || $s->{lastrev};
return $self->htmlDenied if !$self->authCan('staffedit')
|| $sid && (($s->{locked} || $s->{hidden}) && !$self->authCan('dbmod'));
@@ -384,4 +385,3 @@ sub staffxml {
}
1;
-__END__
diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm
index 8869d1a9..c383be78 100644
--- a/lib/VNDB/Handler/VNEdit.pm
+++ b/lib/VNDB/Handler/VNEdit.pm
@@ -79,7 +79,7 @@ sub edit {
my $v = $vid && $self->dbVNGet(id => $vid, what => 'extended screenshots relations anime credits changes', $rev ? (rev => $rev) : ())->[0];
return $self->resNotFound if $vid && !$v->{id};
- $rev = undef if !$vid || $v->{cid} == $v->{latest};
+ $rev = undef if !$vid || $v->{lastrev};
return $self->htmlDenied if !$self->authCan('edit')
|| $vid && (($v->{locked} || $v->{hidden}) && !$self->authCan('dbmod'));
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index 9c85f922..cf8a50af 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -187,8 +187,7 @@ my @rel_cols = (
sub releases {
my($self, $vid) = @_;
- my $v = $self->dbVNGet(
- id => $vid)->[0];
+ my $v = $self->dbVNGet(id => $vid)->[0];
return $self->resNotFound if !$v->{id};
my $title = mt('_vnpage_rel_title', $v->{title});
@@ -334,9 +333,10 @@ sub page {
my $staff = $rev && $rev eq 'staff';
$rev = undef if $char || $staff;
- my $v = $self->dbVNGet(
+ my $method = $rev ? 'dbVNGetRev' : 'dbVNGet';
+ my $v = $self->$method(
id => $vid,
- what => 'extended anime relations screenshots rating ranking'.($staff || $rev ? ' credits' : '').($rev ? ' changes' : ''),
+ what => 'extended anime relations screenshots rating ranking'.($staff || $rev ? ' credits' : ''),
$rev ? (rev => $rev) : (),
)->[0];
return $self->resNotFound if !$v->{id};
@@ -508,8 +508,8 @@ sub _revision {
my($self, $v, $rev) = @_;
return if !$rev;
- my $prev = $rev && $rev > 1 && $self->dbVNGet(
- id => $v->{id}, rev => $rev-1, what => 'extended anime relations screenshots credits changes'
+ my $prev = $rev && $rev > 1 && $self->dbVNGetRev(
+ id => $v->{id}, rev => $rev-1, what => 'extended anime relations screenshots credits'
)->[0];
$self->htmlRevision('v', $prev, $v,