Not working in hypnotoad but working in morbo?

This commit is contained in:
Ryan Voots 2020-09-14 00:27:47 -04:00
parent 3735cf5aad
commit e26ca23d73
3 changed files with 23 additions and 5 deletions

View file

@ -23,13 +23,15 @@ sub display ($self) {
# Render template "example/welcome.html.ep" with message
my ($real_server, $real_namespace, $server, $namespace) = $self->_get_namespace();
my $sort=$self->param("sort")//"original_subject";
my $factoids;
if (my $cached = $self->app->mcache->get("facts:$server:$namespace")) {
say ("Found Cached factoid list");
$factoids = $cached;
} else {
say ("Doing DB Lookup");
$factoids = $self->app->factdb->get_factoids($real_server, $real_namespace);
say ("Doing DB Lookup, $sort");
$factoids = $self->app->factdb->get_factoids($real_server, $real_namespace, $sort);
$self->app->mcache->set("facts:$server:$namespace", $factoids);
}

View file

@ -14,7 +14,16 @@ has 'pg' => sub {
Mojo::Pg->new($self->dsn)
};
sub get_factoids($self, $server, $namespace) {
sub get_factoids($self, $server, $namespace, $sort) {
my $lookup = {
subject => "original_subject",
id => "factoid_id",
predicate => "predicate",
};
my $real_sort = $lookup->{$sort} // "original_subject";
my $data = $self->pg->db->query(
"WITH RECURSIVE factoid_lookup_order_inner (depth, namespace, server, alias_namespace, alias_server, parent_namespace, parent_server, recursive, gen_server, gen_namespace) AS (
SELECT 0 AS depth, namespace, server, alias_namespace, alias_server, parent_namespace, parent_server, recursive, generated_server, generated_namespace
@ -42,7 +51,7 @@ get_latest_factoid (depth, factoid_id, subject, copula, predicate, author, modif
SELECT * FROM get_latest_factoid WHERE NOT deleted
AND predicate IS NOT NULL
AND predicate <> ' '
AND predicate <> '' ORDER BY original_subject ASC"
AND predicate <> '' ORDER BY ".$real_sort." ASC"
, $namespace, $server)->hashes;
return $data;

View file

@ -46,7 +46,14 @@ These are the factoids for [%- format_namespace($server, $namespace) -%].
</p>
<table class="table table-striped table-bordered table-sm">
<thead class="thead-dark"><th>factoid_id</th><th>subject</th><th>copula</th><th>predicate</th><th>history</th><th>from namespace</th></thead>
<thead class="thead-dark">
<th><a href="[%- ns_url($server, $namespace) -%]/list?sort=id">factoid_id</a></th>
<th><a href="[%- ns_url($server, $namespace) -%]/list?sort=subject">subject</a></th>
<th>copula</th>
<th><a href="[%- ns_url($server, $namespace) -%]/list?sort=predicate">predicate</a></th>
<th>history</th>
<th>from namespace</th>
</thead>
<tbody>
[%- for fact IN ($factoids.to_array) -%]
[%- row($fact) -%]