]> git.mxchange.org Git - friendica.git/commitdiff
OEmbed and parse_url are now cached in dedicated tables
authorMichael Vogel <icarus@dabo.de>
Thu, 14 Jan 2016 22:59:51 +0000 (23:59 +0100)
committerMichael Vogel <icarus@dabo.de>
Thu, 14 Jan 2016 22:59:51 +0000 (23:59 +0100)
boot.php
include/dbstructure.php
include/items.php
include/oembed.php
mod/parse_url.php
update.php

index ae98e9240997cc03a8b0043c91463b40f4760567..049dc911054ab294bafbaa0c3bb4cbd6d6fbd1c9 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -36,7 +36,7 @@ define ( 'FRIENDICA_PLATFORM',     'Friendica');
 define ( 'FRIENDICA_CODENAME',     'Asparagus');
 define ( 'FRIENDICA_VERSION',      '3.5-dev' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.23'    );
-define ( 'DB_UPDATE_VERSION',      1192      );
+define ( 'DB_UPDATE_VERSION',      1193      );
 
 /**
  * @brief Constant with a HTML line break.
index 7fed50e741c9192577201eee6370943295750200..35bacd7f834bd5c6b628eae34e57ed1b8e19ce52 100644 (file)
@@ -1021,6 +1021,26 @@ function db_definition() {
                                        "receiver-uid" => array("receiver-uid"),
                                        )
                        );
+       $database["oembed"] = array(
+                       "fields" => array(
+                                       "url" => array("type" => "varchar(255)", "not null" => "1", "primary" => "1"),
+                                       "content" => array("type" => "text", "not null" => "1"),
+                                       ),
+                       "indexes" => array(
+                                       "PRIMARY" => array("url"),
+                                       )
+                       );
+       $database["parsed_url"] = array(
+                       "fields" => array(
+                                       "url" => array("type" => "varchar(255)", "not null" => "1", "primary" => "1"),
+                                       "guessing" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
+                                       "oembed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
+                                       "content" => array("type" => "text", "not null" => "1"),
+                                       ),
+                       "indexes" => array(
+                                       "PRIMARY" => array("url", "guessing", "oembed"),
+                                       )
+                       );
        $database["pconfig"] = array(
                        "fields" => array(
                                        "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
index 62526d44865dc3fd455d8bdb83c29ba1cdb7d733..a74ca3b36052ec826203124fc633daaee0a77956 100644 (file)
@@ -968,12 +968,7 @@ function add_page_info_data($data) {
 function query_page_info($url, $no_photos = false, $photo = "", $keywords = false, $keyword_blacklist = "") {
        require_once("mod/parse_url.php");
 
-       $data = Cache::get("parse_url:".$url);
-       if (is_null($data)){
-               $data = parseurl_getsiteinfo($url, true);
-               Cache::set("parse_url:".$url,serialize($data), CACHE_DAY);
-       } else
-               $data = unserialize($data);
+       $data = parseurl_getsiteinfo_cached($url, true);
 
        if ($photo != "")
                $data["images"][0]["src"] = $photo;
index c848a4580c9dafc407c649fc2a36e0e2130eb399..51130645812965977066bdbf0e99c5c621019ae1 100755 (executable)
@@ -13,7 +13,13 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){
 
        $a = get_app();
 
-       $txt = Cache::get($a->videowidth . $embedurl);
+       $r = q("SELECT * FROM `oembed` WHERE `url` = '%s'",
+               dbesc(normalise_link($embedurl)));
+
+       if ($r)
+               $txt = $r[0]["content"];
+       else
+               $txt = Cache::get($a->videowidth . $embedurl);
 
        // These media files should now be caught in bbcode.php
        // left here as a fallback in case this is called from another source
@@ -66,8 +72,14 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){
 
                if ($txt[0]!="{")
                        $txt='{"type":"error"}';
-               else    //save in cache
+               else {  //save in cache
+                       $j = json_decode($txt);
+                       if ($j->type != "error")
+                               q("INSERT INTO `oembed` (`url`, `content`) VALUES ('%s', '%s')",
+                                       dbesc(normalise_link($embedurl)), dbesc($txt));
+
                        Cache::set($a->videowidth . $embedurl,$txt, CACHE_DAY);
+               }
        }
 
        $j = json_decode($txt);
@@ -85,7 +97,7 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){
        // If fetching information doesn't work, then improve via internal functions
        if (($j->type == "error") OR ($no_rich_type AND ($j->type == "rich"))) {
                require_once("mod/parse_url.php");
-               $data = parseurl_getsiteinfo($embedurl, true, false);
+               $data = parseurl_getsiteinfo_cached($embedurl, true, false);
                $j->type = $data["type"];
 
                if ($j->type == "photo") {
index 28869b4c128d7ecd3d1f5b8436297b8b11aad5c5..8aa0c17ee1db0fa2ac011177ee6afd2945703c2f 100644 (file)
@@ -56,7 +56,15 @@ function completeurl($url, $scheme) {
 
 function parseurl_getsiteinfo_cached($url, $no_guessing = false, $do_oembed = true) {
 
-       $data = Cache::get("parse_url:".$no_guessing.":".$do_oembed.":".$url);
+       if ($url == "")
+               return false;
+
+       $r = q("SELECT * FROM `parsed_url` WHERE `url` = '%s' AND `guessing` = %d AND `oembed` = %d",
+               dbesc(normalise_link($url)), intval(!$no_guessing), intval($do_oembed));
+
+       if ($r)
+               $data = $r[0]["content"];
+
        if (!is_null($data)) {
                $data = unserialize($data);
                return $data;
@@ -64,7 +72,8 @@ function parseurl_getsiteinfo_cached($url, $no_guessing = false, $do_oembed = tr
 
        $data = parseurl_getsiteinfo($url, $no_guessing, $do_oembed);
 
-       Cache::set("parse_url:".$no_guessing.":".$do_oembed.":".$url,serialize($data), CACHE_DAY);
+       q("INSERT INTO `parsed_url` (`url`, `guessing`, `oembed`, `content`) VALUES ('%s', %d, %d, '%s')",
+               dbesc(normalise_link($url)), intval(!$no_guessing), intval($do_oembed), dbesc(serialize($data)));
 
        return $data;
 }
index 197e78de5c44f88f6262fd5e944f12a5f62c6aea..a825c82e9294657529aad6917f8d5cf56ce8a1ce 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-define( 'UPDATE_VERSION' , 1192 );
+define( 'UPDATE_VERSION' , 1193 );
 
 /**
  *