summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2014-12-22 12:06:55 +0100
committerYorhel <git@yorhel.nl>2014-12-22 12:06:55 +0100
commitb646361f63e066c6859a1f05e29af7d9c812a13a (patch)
tree89e848a66ad36c710a0ec5d0f3f9a9330d7c0368 /lib
parent12338003bde24a3a263abe8caca71b1836ecee83 (diff)
DB: Merge name/title fetching in main fetching functions
And call bbSubstLinks() from Handler::Discussions rather than DB::Discussions - it's not a transformation that the DB layer should do, IMO.
Diffstat (limited to 'lib')
-rw-r--r--lib/VNDB/DB/Chars.pm16
-rw-r--r--lib/VNDB/DB/Discussions.pm4
-rw-r--r--lib/VNDB/DB/Producers.pm15
-rw-r--r--lib/VNDB/DB/VN.pm14
-rw-r--r--lib/VNDB/Handler/Discussions.pm2
-rw-r--r--lib/VNDB/Util/Misc.pm6
-rw-r--r--lib/VNDBUtil.pm3
7 files changed, 15 insertions, 45 deletions
diff --git a/lib/VNDB/DB/Chars.pm b/lib/VNDB/DB/Chars.pm
index f387b044..0f4120fd 100644
--- a/lib/VNDB/DB/Chars.pm
+++ b/lib/VNDB/DB/Chars.pm
@@ -5,7 +5,7 @@ use strict;
use warnings;
use Exporter 'import';
-our @EXPORT = qw|dbCharGet dbCharRevisionInsert dbCharImageId dbCharNames|;
+our @EXPORT = qw|dbCharGet dbCharRevisionInsert dbCharImageId|;
# options: id rev instance tagspoil trait_inc trait_exc char what results page gender bloodt
@@ -25,7 +25,8 @@ sub dbCharGet {
my %where = (
!$o{id} && !$o{rev} ? ( 'c.hidden = FALSE' => 1 ) : (),
- $o{id} ? ( 'c.id = ?' => $o{id} ) : (),
+ $o{id} ? (
+ 'c.id IN(!l)' => [ ref $o{id} ? $o{id} : [$o{id}] ] ) : (),
$o{rev} ? ( 'h.rev = ?' => $o{rev} ) : (),
$o{notid} ? ( 'c.id <> ?' => $o{notid} ) : (),
$o{instance} ? ( 'cr.main = ?' => $o{instance} ) : (),
@@ -138,16 +139,5 @@ sub dbCharImageId {
}
-sub dbCharNames {
- my ($self, @ids) = @_;
- return $self->dbAll(q|
- SELECT c.id, cr.name
- FROM chars c
- JOIN chars_rev cr ON cr.id = c.latest
- WHERE c.id IN (!l)|, \@ids
- );
-}
-
-
1;
diff --git a/lib/VNDB/DB/Discussions.pm b/lib/VNDB/DB/Discussions.pm
index d1462249..9da25384 100644
--- a/lib/VNDB/DB/Discussions.pm
+++ b/lib/VNDB/DB/Discussions.pm
@@ -4,7 +4,6 @@ package VNDB::DB::Discussions;
use strict;
use warnings;
use Exporter 'import';
-use VNDB::Util::Misc 'bbSubstLinks';
our @EXPORT = qw|dbThreadGet dbThreadEdit dbThreadAdd dbPostGet dbPostEdit dbPostAdd dbThreadCount|;
@@ -215,7 +214,7 @@ sub dbPostEdit {
my($self, $tid, $num, %o) = @_;
my %set = (
- 'msg = ?' => bbSubstLinks($self, $o{msg}),
+ 'msg = ?' => $o{msg},
'edited = to_timestamp(?)' => $o{lastmod},
'hidden = ?' => $o{hidden}?1:0,
);
@@ -237,7 +236,6 @@ sub dbPostAdd {
my $num = $self->dbRow('SELECT num FROM threads_posts WHERE tid = ? ORDER BY num DESC LIMIT 1', $tid)->{num};
$num = $num ? $num+1 : 1;
$o{uid} ||= $self->authInfo->{id};
- $o{msg} = bbSubstLinks($self, $o{msg});
$self->dbExec(q|
INSERT INTO threads_posts (tid, num, uid, msg)
diff --git a/lib/VNDB/DB/Producers.pm b/lib/VNDB/DB/Producers.pm
index 7d4b6897..86ed124e 100644
--- a/lib/VNDB/DB/Producers.pm
+++ b/lib/VNDB/DB/Producers.pm
@@ -5,7 +5,7 @@ use strict;
use warnings;
use Exporter 'import';
-our @EXPORT = qw|dbProducerGet dbProducerRevisionInsert dbProducerNames|;
+our @EXPORT = qw|dbProducerGet dbProducerRevisionInsert|;
# options: results, page, id, search, char, rev
@@ -25,7 +25,7 @@ sub dbProducerGet {
!$o{id} && !$o{rev} ? (
'p.hidden = FALSE' => 1 ) : (),
$o{id} ? (
- 'p.id = ?' => $o{id} ) : (),
+ 'p.id IN(!l)' => [ ref $o{id} ? $o{id} : [$o{id}] ] ) : (),
$o{search} ? (
'(pr.name ILIKE ? OR pr.original ILIKE ? OR pr.alias ILIKE ?)', [ map '%%'.$o{search}.'%%', 1..3 ] ) : (),
$o{char} ? (
@@ -94,16 +94,5 @@ sub dbProducerRevisionInsert {
}
-sub dbProducerNames {
- my($self, @ids) = @_;
- return $self->dbAll(q|
- SELECT p.id, pr.name
- FROM producers p
- JOIN producers_rev pr ON pr.id = p.latest
- WHERE p.id IN (!l)|, \@ids
- );
-}
-
-
1;
diff --git a/lib/VNDB/DB/VN.pm b/lib/VNDB/DB/VN.pm
index ecf49f96..aaca4da5 100644
--- a/lib/VNDB/DB/VN.pm
+++ b/lib/VNDB/DB/VN.pm
@@ -7,7 +7,7 @@ use Exporter 'import';
use VNDB::Func 'gtintype', 'normalize_query';
use Encode 'decode_utf8';
-our @EXPORT = qw|dbVNGet dbVNRevisionInsert dbVNImageId dbScreenshotAdd dbScreenshotGet dbScreenshotRandom dbVNHasChar dbVNTitles|;
+our @EXPORT = qw|dbVNGet dbVNRevisionInsert dbVNImageId dbScreenshotAdd dbScreenshotGet dbScreenshotRandom dbVNHasChar|;
# Options: id, rev, char, search, length, lang, olang, plat, tag_inc, tag_exc, tagspoil,
@@ -32,7 +32,7 @@ sub dbVNGet {
my @where = (
$o{id} ? (
- 'v.id = ?' => $o{id} ) : (),
+ 'v.id IN(!l)' => [ ref $o{id} ? $o{id} : [$o{id}] ] ) : (),
$o{rev} ? (
'c.rev = ?' => $o{rev} ) : (),
$o{char} ? (
@@ -291,15 +291,5 @@ sub dbVNHasChar {
}
-sub dbVNTitles {
- my ($self, @vids) = @_;
- return $self->dbAll(q|
- SELECT v.id, vr.title
- FROM vn v
- JOIN vn_rev vr ON vr.id = v.latest
- WHERE v.id IN (!l)|, \@vids
- );
-}
-
1;
diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm
index 477e6bfa..e1645fd5 100644
--- a/lib/VNDB/Handler/Discussions.pm
+++ b/lib/VNDB/Handler/Discussions.pm
@@ -215,7 +215,7 @@ sub edit {
# create/edit post
my %post = (
- msg => $frm->{msg},
+ msg => $self->bbSubstLinks($frm->{msg}),
hidden => $num != 1 && $frm->{hidden},
lastmod => !$num || $frm->{nolastmod} ? 0 : time,
);
diff --git a/lib/VNDB/Util/Misc.pm b/lib/VNDB/Util/Misc.pm
index a3a156d3..612178c3 100644
--- a/lib/VNDB/Util/Misc.pm
+++ b/lib/VNDB/Util/Misc.pm
@@ -155,13 +155,13 @@ sub bbSubstLinks {
return $msg unless %lookup;
# lookup parsed links
if ($lookup{v}) {
- $links{"v$_->{id}"} = $_->{title} for (@{$self->dbVNTitles(keys %{$lookup{v}})});
+ $links{"v$_->{id}"} = $_->{title} for (@{$self->dbVNGet(id => [keys %{$lookup{v}}])});
}
if ($lookup{c}) {
- $links{"c$_->{id}"} = $_->{name} for (@{$self->dbCharNames(keys %{$lookup{c}})});
+ $links{"c$_->{id}"} = $_->{name} for (@{$self->dbCharGet(id => [keys %{$lookup{c}}])});
}
if ($lookup{p}) {
- $links{"p$_->{id}"} = $_->{name} for (@{$self->dbProducerNames(keys %{$lookup{p}})});
+ $links{"p$_->{id}"} = $_->{name} for (@{$self->dbProducerGet(id => [keys %{$lookup{p}}])});
}
if ($lookup{g}) {
$links{"g$_->{id}"} = $_->{name} for (@{$self->dbTagGet(id => [keys %{$lookup{g}}])});
diff --git a/lib/VNDBUtil.pm b/lib/VNDBUtil.pm
index e81971a6..0c3d5eb3 100644
--- a/lib/VNDBUtil.pm
+++ b/lib/VNDBUtil.pm
@@ -27,6 +27,9 @@ sub shorten {
# [code] .. [/code]
# v+, v+.+
# http://../
+# XXX: Make sure to sync any changes in the formating with
+# VNDB::Util::Misc::bbSubstLinks() if necessary. Or, alternatively, abstract
+# parsing into a separate function as per http://beta.vndb.org/t5564.12
sub bb2html {
my($raw, $maxlength, $charspoil) = @_;
$raw =~ s/\r//g;