Browse Source

Rewrite screenshot adding in new torrents to use nicer SQL

spaghetti 7 years ago
parent
commit
c9b6bcf0be
2 changed files with 24 additions and 20 deletions
  1. 9
    10
      classes/mysql.class.php
  2. 15
    10
      sections/upload/upload_handle.php

+ 9
- 10
classes/mysql.class.php View File

149
   public $LinkID = false;
149
   public $LinkID = false;
150
   protected $QueryID = false;
150
   protected $QueryID = false;
151
   protected $StatementID = false;
151
   protected $StatementID = false;
152
+  protected $PreparedQuery = false;
152
   protected $Record = [];
153
   protected $Record = [];
153
   protected $Row;
154
   protected $Row;
154
   protected $Errno = 0;
155
   protected $Errno = 0;
203
     mysqli_set_charset($this->LinkID, "utf8");
204
     mysqli_set_charset($this->LinkID, "utf8");
204
   }
205
   }
205
 
206
 
206
-  function query_p($Query, &...$BindVars) {
207
-    $QueryStartTime = microtime(true);
207
+  function prepare_query($Query, &...$BindVars) {
208
     $this->connect();
208
     $this->connect();
209
 
209
 
210
     $this->StatementID = mysqli_prepare($this->LinkID, $Query);
210
     $this->StatementID = mysqli_prepare($this->LinkID, $Query);
216
       }
216
       }
217
       mysqli_stmt_bind_param($this->StatementID, $Types, ...$BindVars);
217
       mysqli_stmt_bind_param($this->StatementID, $Types, ...$BindVars);
218
     }
218
     }
219
+    $this->PreparedQuery = $Query;
220
+    return $this->StatementID;
221
+  }
222
+
223
+  function exec_prepared_query() {
224
+    $QueryStartTime = microtime(true);
219
     mysqli_stmt_execute($this->StatementID);
225
     mysqli_stmt_execute($this->StatementID);
220
     $this->QueryID = mysqli_stmt_get_result($this->StatementID);
226
     $this->QueryID = mysqli_stmt_get_result($this->StatementID);
221
     $QueryRunTime = (microtime(true) - $QueryStartTime) * 1000;
227
     $QueryRunTime = (microtime(true) - $QueryStartTime) * 1000;
222
-    $this->Queries[] = [$Query, $QueryRunTime, null];
228
+    $this->Queries[] = [$this->PreppedQuery, $QueryRunTime, null];
223
     $this->Time += $QueryRunTime;
229
     $this->Time += $QueryRunTime;
224
-
225
-    return $this->StatementID;
226
   }
230
   }
227
 
231
 
228
   function query($Query, &...$BindVars) {
232
   function query($Query, &...$BindVars) {
291
     return $this->QueryID;
295
     return $this->QueryID;
292
   }
296
   }
293
 
297
 
294
-  function reexec_query() {
295
-    mysqli_stmt_execute($this->StatementID);
296
-    $this->QueryID = mysqli_stmt_get_result($this->StatementID);
297
-  }
298
-
299
   function query_unb($Query) {
298
   function query_unb($Query) {
300
     $this->connect();
299
     $this->connect();
301
     mysqli_real_query($this->LinkID, $Query);
300
     mysqli_real_query($this->LinkID, $Query);

+ 15
- 10
sections/upload/upload_handle.php View File

395
   $Cache->increment('stats_group_count');
395
   $Cache->increment('stats_group_count');
396
 
396
 
397
   // Add screenshots
397
   // Add screenshots
398
-  $Screenshots = array_slice(array_filter(array_map("db_string", array_map("trim", array_unique(explode("\n", $T['Screenshots'])))), function ($s) { return preg_match('/^'.IMAGE_REGEX.'$/i', $s); }), 0, 10);
399
-
400
-  $values = [];
401
-  foreach ($Screenshots as $s) {
402
-    $values[] = "(" . $GroupID . ", " . $LoggedUser['ID'] . ", NOW(), '" . $s . "')";
403
-  }
404
-
405
-  if (!empty($values)) {
406
-    $DB->query("
398
+  $Screenshots = explode("\n", $T['Screenshots']);
399
+  $Screenshots = array_map("trim", $Screenshots);
400
+  $Screenshots = array_filter($Screenshots, function($s) {
401
+    return preg_match('/^'.IMAGE_REGEX.'$/i', $s);
402
+  });
403
+  $Screenshots = array_unique($Screenshots);
404
+  $Screenshots = array_slice($Screenshots, 0, 10);
405
+
406
+  if (!empty($Screenshots)) {
407
+    $Screenshot = '';
408
+    $DB->prepare_query("
407
       INSERT INTO torrents_screenshots
409
       INSERT INTO torrents_screenshots
408
         (GroupID, UserID, Time, Image)
410
         (GroupID, UserID, Time, Image)
409
-      VALUES " . implode(", ", $values));
411
+      VALUES (?, ?, NOW(), ?)", $GroupID, $LoggedUser['ID'], $Screenshot);
412
+    foreach ($Screenshots as $Screenshot) {
413
+      $DB->exec_prepared_query();
414
+    }
410
   }
415
   }
411
 
416
 
412
 } else {
417
 } else {

Loading…
Cancel
Save