« blib/lib/App/Netdisco/Web/Plugin/Report/PortLog.pm
↑ Summary
blib/lib/App/Netdisco/DB/Result/Subnet.pm »
| 1 | use utf8; | ||
| 2 | package App::Netdisco::DB; | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | use base 'DBIx::Class::Schema'; | ||
| 8 | |||
| 9 | __PACKAGE__->load_namespaces( | ||
| 10 | default_resultset_class => 'ResultSet', | ||
| 11 | ); | ||
| 12 | |||
| 13 | our # try to hide from kwalitee | ||
| 14 | $VERSION = 108; # schema version used for upgrades, keep as integer | ||
| 15 | |||
| 16 | use Path::Class; | ||
| 17 | use File::ShareDir 'dist_dir'; | ||
| 18 | |||
| 19 | our $schema_versions_dir = Path::Class::Dir->new( dist_dir('App-Netdisco') ) | ||
| 20 | ->subdir('schema_versions')->stringify; | ||
| 21 | |||
| 22 | __PACKAGE__->load_components(qw/ | ||
| 23 | +App::Netdisco::DB::SchemaVersioned | ||
| 24 | +App::Netdisco::DB::ExplicitLocking | ||
| 25 | /); | ||
| 26 | |||
| 27 | __PACKAGE__->upgrade_directory($schema_versions_dir); | ||
| 28 | |||
| 29 | =head1 METHODS | ||
| 30 | |||
| 31 | =head2 without_jit( $code ) | ||
| 32 | |||
| 33 | Runs C<$code> in a transaction with PostgreSQL's JIT compilation off, and | ||
| 34 | returns what C<$code> returns. For queries whose cost estimate starts JIT | ||
| 35 | compilation that takes longer than the query itself. | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | sub without_jit { | ||
| 40 | my ($self, $code) = @_; | ||
| 41 | return $self->txn_do(sub { | ||
| 42 | my $dbh = $self->storage->dbh; | ||
| 43 | # PostgreSQL 10 has no jit setting; drop this check when the floor is 14 | ||
| 44 | $dbh->do('SET LOCAL jit = off') | ||
| 45 | if ($dbh->{pg_server_version} || 0) >= 110000; | ||
| 46 | return $code->(); | ||
| 47 | }); | ||
| 48 | } | ||
| 49 | |||
| 50 | 1; |