やっぱりちゃんと Schema::Pg を作ろうと思い立ち、作業してみたらちょっと悩む。
Schema/SQLite/*.pm の belongs_to, has_many で
__PACKAGE__->belongs_to( feed => 'Plagger::Schema::SQLite::Feed' );
こんな風に hard code してあるところはどうしよう?
単に SQLite/*.pm をまんま Pg/*.pm としてコピーして s/SQLite/Pg/ すればもちろんできるけど、それはなあ。
それ以外の作業は以下の通りで。
entry.date / feed.updated の infrate, deflate には DateTime::Format::Pg を使う(DB 側の型は timestamp )
__PACKAGE__->inflate_column( date => { inflate => sub { my $d = DateTime::Format::Pg->parse_timestamp( shift ); $d->set_time_zone('local'); $d; }, deflate => sub { my $d = shift; $d->set_time_zone('local'); DateTime::Format::Pg->format_timestamp( $d ); }, } );
PlaggerLDR/Controller/[API|Nofify].pm にも Schema::SQLite が hard code されているので、config を読むように patch.
-use Plagger::Schema::SQLite; +require UNIVERSAL::require; my $config = YAML::LoadFile( PlaggerLDR->path_to('root', 'config.yaml') ); my $module = first { $_->{module} eq 'Store::DBIC' } @{$config->{plugins}}; -my $schema = Plagger::Schema::SQLite->connect(@{$module->{config}->{connect_info}}); +my $class = $module->{config}->{schema_class}; +$class->require; +my $schema = $class->connect(@{$module->{config}->{connect_info}});
ついでに。発行される SQL を眺めていると、シーケンシャルサーチになってしまうクエリが多い。
以下のインデクスがあるとデータが増えても重くなりにくいはず。
CREATE INDEX entry_idx ON entry (feed, read); CREATE INDEX entry_meta_idx ON entry_meta (entry); CREATE INDEX entry_tag_idx ON entry_tag (entry);