On Sun, Feb 4, 2018 at 1:16 AM, Stefan Adams <[email protected]> wrote:
> as Sebastian said at the beginning, it's really all that useful for
> Mojo::Pg.
>
My use case for it is that I'm building a web service cache. We use a SaaS
ERP-type database that provides a SOAP API that's super slow. The API
documentation even recommends caching the data to a local database for
better performance, so I'm doing exactly that. An hourly cronjob will kick
off a Mojo app command that syncs the SaaS database to a local database.
There's nothing I can do to speed up the 500-record limit retrieval, but if
there's anything I can do to speed up the insert so I can move on to the
next batch of records, that'd be great! Actually, there's one thing the
SaaS database provides that helps me to speed up the retrieval: and that's
fetching only records that have changed since a provided last_modified date.
A bulk_upsert would be great, too. I haven't tested this, but it seems
like it would work?
sub bulk_upsert {
my ($self, $table, $records, $options) = @_;
my ($stmt) = $self->pg->abstract->insert($table, $records->[0],
{on_conflict => [$table, $records->[0]], %$options});
eval {
my $tx = $self->pg->db->begin;
my $i = $self->pg->db->dbh->prepare($stmt);
while ( my $next = shift @$records ) {
$i->execute(@$next{sort keys %$next}, @$next{sort keys %$next});
}
$tx->commit;
};
return $@ if $@;
}
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.