From 72c3d3da457d24ec39e6a9fa149aad3e39fb7a4e Mon Sep 17 00:00:00 2001
From: Alexandre Morignot <erdnaxeli@cervoi.se>
Date: Tue, 8 Nov 2016 22:31:30 +0100
Subject: [PATCH] Save too big research to be viewed on the website

---
 PlayBot/commands/get.pm |  3 ++-
 PlayBot/utils/db/get.pm | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/PlayBot/commands/get.pm b/PlayBot/commands/get.pm
index babc641..384d581 100644
--- a/PlayBot/commands/get.pm
+++ b/PlayBot/commands/get.pm
@@ -30,7 +30,8 @@ sub exec {
             and $rows > 10
             and not $query->force)
     {
-        $irc->yield(privmsg => $chan => "trop de résultats ($rows), utiliser -f pour forcer la recherche");
+        my $search_name = $db_query->make_view($query);
+        $irc->yield(privmsg => $chan => "trop de résultats ($rows), utilise -f pour forcer la recherche ou va voir ici : http://nightiies.iiens.net/links/search/$search_name");
         return;
     }
 
diff --git a/PlayBot/utils/db/get.pm b/PlayBot/utils/db/get.pm
index 1d00e88..6fd1a68 100644
--- a/PlayBot/utils/db/get.pm
+++ b/PlayBot/utils/db/get.pm
@@ -85,6 +85,28 @@ sub get_rows {
     return $rows;
 }
 
+sub make_view {
+    my ($self, $query) = @_;
+
+    my $dbh = PlayBot::utils::db::get_new_session();
+    $dbh->{AutoCommit} = 0;
+
+    my ($request, @args) = $self->_prepare_request($query);
+    my $view_name =  join'', map +(0..9,'a'..'z','A'..'Z')[rand(10+26*2)], 1..32;
+    my $sth = $dbh->prepare('create view '.$view_name.' AS '.$request);
+    $sth->execute(@args);
+
+    $dbh->do('create event clear'.$view_name.'
+        on schedule at current_timestamp + interval 1 hour
+        do
+            drop view '.$view_name);
+
+    $dbh->commit;
+    $dbh->disconnect;
+
+    return $view_name;
+}
+
 sub _get_next {
     my ($self, $query) = @_;
     my $chan = $query->chan;
-- 
GitLab