oembed cache: don't store the url (which may need to be truncated), store a hash instead. This will allow us to convert the table to utf8mb4 without running into mysql key length restrictions as well as dealing with the potential ambiguity of truncated urls.

This commit is contained in:
zotlabs 2017-04-18 18:31:10 -07:00
parent a037758245
commit 53bd0146bb

View File

@ -9,10 +9,10 @@ namespace Zotlabs\Lib;
class Cache { class Cache {
public static function get($key) { public static function get($key) {
$key = substr($key,0,254); $hash = hash('whirlpool',$key);
$r = q("SELECT v FROM cache WHERE k = '%s' limit 1", $r = q("SELECT v FROM cache WHERE k = '%s' limit 1",
dbesc($key) dbesc($hash)
); );
if ($r) if ($r)
@ -22,20 +22,20 @@ class Cache {
public static function set($key,$value) { public static function set($key,$value) {
$key = substr($key,0,254); $hash = hash('whirlpool',$key);
$r = q("SELECT * FROM cache WHERE k = '%s' limit 1", $r = q("SELECT * FROM cache WHERE k = '%s' limit 1",
dbesc($key) dbesc($hash)
); );
if($r) { if($r) {
q("UPDATE cache SET v = '%s', updated = '%s' WHERE k = '%s'", q("UPDATE cache SET v = '%s', updated = '%s' WHERE k = '%s'",
dbesc($value), dbesc($value),
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc($key)); dbesc($hash));
} }
else { else {
q("INSERT INTO cache ( k, v, updated) VALUES ('%s','%s','%s')", q("INSERT INTO cache ( k, v, updated) VALUES ('%s','%s','%s')",
dbesc($key), dbesc($hash),
dbesc($value), dbesc($value),
dbesc(datetime_convert())); dbesc(datetime_convert()));
} }