Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Made a start at report cacheing

  • Loading branch information...
commit a3b9539f1165dcb25bf95d334baf212c3f0be352 1 parent 2922831
Ray Miller authored
View
28 ddl/templates/versions/8/audit-up.sql
@@ -0,0 +1,28 @@
+CREATE TABLE audit.cached_reports (
+audit_op CHAR(1) NOT NULL CHECK (audit_op IN ('D','I','U')),
+audit_user TEXT NOT NULL,
+audit_stamp TIMESTAMP NOT NULL,
+audit_txid INTEGER NOT NULL,
+id character(36),
+report_class text,
+params text,
+expires timestamp without time zone
+);
+GRANT SELECT ON audit.cached_reports TO "[% ro_role %]";
+GRANT SELECT,INSERT ON audit.cached_reports TO "[% rw_role %]";
+CREATE OR REPLACE FUNCTION public.process_cached_reports_audit()
+RETURNS TRIGGER AS $cached_reports_audit$
+ BEGIN
+ IF (TG_OP = 'DELETE') THEN
+ INSERT INTO audit.cached_reports SELECT 'D', user, now(), txid_current(), OLD.*;
+ ELSIF (TG_OP = 'UPDATE') THEN
+ INSERT INTO audit.cached_reports SELECT 'U', user, now(), txid_current(), NEW.*;
+ ELSIF (TG_OP = 'INSERT') THEN
+ INSERT INTO audit.cached_reports SELECT 'I', user, now(), txid_current(), NEW.*;
+ END IF;
+ RETURN NULL;
+ END;
+$cached_reports_audit$ LANGUAGE plpgsql;
+CREATE TRIGGER cached_reports_audit
+AFTER INSERT OR UPDATE OR DELETE ON public.cached_reports
+ FOR EACH ROW EXECUTE PROCEDURE public.process_cached_reports_audit();
View
9 ddl/templates/versions/8/up.sql
@@ -0,0 +1,9 @@
+CREATE TABLE cached_reports (
+ id CHAR(36) PRIMARY KEY,
+ report_class TEXT NOT NULL,
+ params TEXT NOT NULL,
+ expires TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP + INTERVAL '8 hours',
+ UNIQUE( report_class, params )
+);
+GRANT SELECT ON cached_reports TO "[% ro_role %]";
+GRANT SELECT, INSERT, UPDATE, DELETE ON cached_reports TO "[% rw_role %]";
View
6 lib/LIMS2/Report.pm
@@ -16,6 +16,12 @@ use Log::Log4perl qw( :easy );
use LIMS2::Exception::System;
use LIMS2::Exception::Validation;
+sub cached_report {
+ my %args = @_;
+
+
+}
+
sub generator_for {
my ( $report, $model, $params ) = @_;
View
61 lib/LIMS2/WebApp/Controller/User/Report.pm
@@ -27,6 +27,67 @@ Catalyst Controller.
=cut
+=head1 GET /user/report/cache/sync/$REPORT
+
+Retrieve a cached report. Generate the report synchronously if there is no vaild copy in the cache.
+
+=cut
+
+sub cached_sync_report :Path( '/user/report/cache/sync' ) :Args(1) {
+ my ( $self, $c, $report ) = @_;
+
+ $self->assert_user_roles( 'read' );
+
+ my $params = $c->request->params;
+ $params->{species} ||= $c->session->{selected_species};
+
+ my $report_id = LIMS2::Report::cached_report(
+ model => $c->model( 'Golgi' ),
+ report => $report,
+ params => $params,
+ output_dir => $self->report_dir,
+ async => 0
+ );
+
+ if ( not defined $report_id ) {
+ $c->flash( error_msg => 'Failed to generate report' );
+ return $c->response->redirect( $c->uri_for( '/' ) );
+ }
+
+ return $c->forward( 'view_report', [ $report_id ] );
+}
+
+=head1 GET /user/report/cache/async/$REPORT
+
+Retrieve a cached report. Generate the report asynchronously if there is no vaild copy in the cache.
+
+=cut
+
+sub cached_async_report :Path( '/user/report/cache/async' ) :Args(1) {
+ my ( $self, $c, $report ) = @_;
+
+ $self->assert_user_roles( 'read' );
+
+ my $params = $c->request->params;
+ $params->{species} ||= $c->session->{selected_species};
+
+ my $report_id = LIMS2::Report::cached_report(
+ model => $c->model( 'Golgi' ),
+ report => $report,
+ params => $params,
+ output_dir => $self->report_dir,
+ async => 1
+ );
+
+ $c->stash(
+ template => 'user/report/await_report.tt',
+ report_name => $report,
+ report_id => $report_id
+ );
+
+ return;
+}
+
=head1 GET /user/report/sync/$REPORT
Synchronously generate the report I<$REPORT>. Forward to an HTML view.
Please sign in to comment.
Something went wrong with that request. Please try again.