Fetch items by given uri

This commit is contained in:
Michael 2019-07-18 06:11:02 +00:00
parent dcebf53ecf
commit 41a1c1c3e6
3 changed files with 77 additions and 9 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2019.09-dev (Dalmatian Bellflower) -- Friendica 2019.09-dev (Dalmatian Bellflower)
-- DB_UPDATE_VERSION 1318 -- DB_UPDATE_VERSION 1319
-- ------------------------------------------ -- ------------------------------------------
@ -605,15 +605,15 @@ CREATE TABLE IF NOT EXISTS `item` (
INDEX `extid` (`extid`(191)), INDEX `extid` (`extid`(191)),
INDEX `uid_id` (`uid`,`id`), INDEX `uid_id` (`uid`,`id`),
INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`), INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`),
INDEX `uid_created` (`uid`,`created`), INDEX `uid_received` (`uid`,`received`),
INDEX `uid_commented` (`uid`,`commented`), INDEX `uid_commented` (`uid`,`commented`),
INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`), INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
INDEX `uid_network_received` (`uid`,`network`,`received`), INDEX `uid_network_received` (`uid`,`network`,`received`),
INDEX `uid_network_commented` (`uid`,`network`,`commented`), INDEX `uid_network_commented` (`uid`,`network`,`commented`),
INDEX `uid_thrparent` (`uid`,`thr-parent`(190)), INDEX `uid_thrparent` (`uid`,`thr-parent`(190)),
INDEX `uid_parenturi` (`uid`,`parent-uri`(190)), INDEX `uid_parenturi` (`uid`,`parent-uri`(190)),
INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`), INDEX `uid_contactid_received` (`uid`,`contact-id`,`received`),
INDEX `authorid_created` (`author-id`,`created`), INDEX `authorid_received` (`author-id`,`received`),
INDEX `ownerid` (`owner-id`), INDEX `ownerid` (`owner-id`),
INDEX `contact-id` (`contact-id`), INDEX `contact-id` (`contact-id`),
INDEX `uid_uri` (`uid`,`uri`(190)), INDEX `uid_uri` (`uid`,`uri`(190)),
@ -667,6 +667,7 @@ CREATE TABLE IF NOT EXISTS `item-content` (
PRIMARY KEY(`id`), PRIMARY KEY(`id`),
UNIQUE INDEX `uri-plink-hash` (`uri-plink-hash`), UNIQUE INDEX `uri-plink-hash` (`uri-plink-hash`),
INDEX `uri` (`uri`(191)), INDEX `uri` (`uri`(191)),
INDEX `plink` (`plink`(191)),
INDEX `uri-id` (`uri-id`) INDEX `uri-id` (`uri-id`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts'; ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts';
@ -1157,15 +1158,15 @@ CREATE TABLE IF NOT EXISTS `thread` (
`bookmark` boolean COMMENT '', `bookmark` boolean COMMENT '',
PRIMARY KEY(`iid`), PRIMARY KEY(`iid`),
INDEX `uid_network_commented` (`uid`,`network`,`commented`), INDEX `uid_network_commented` (`uid`,`network`,`commented`),
INDEX `uid_network_created` (`uid`,`network`,`created`), INDEX `uid_network_received` (`uid`,`network`,`received`),
INDEX `uid_contactid_commented` (`uid`,`contact-id`,`commented`), INDEX `uid_contactid_commented` (`uid`,`contact-id`,`commented`),
INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`), INDEX `uid_contactid_received` (`uid`,`contact-id`,`received`),
INDEX `contactid` (`contact-id`), INDEX `contactid` (`contact-id`),
INDEX `ownerid` (`owner-id`), INDEX `ownerid` (`owner-id`),
INDEX `authorid` (`author-id`), INDEX `authorid` (`author-id`),
INDEX `uid_created` (`uid`,`created`), INDEX `uid_received` (`uid`,`received`),
INDEX `uid_commented` (`uid`,`commented`), INDEX `uid_commented` (`uid`,`commented`),
INDEX `uid_wall_created` (`uid`,`wall`,`created`), INDEX `uid_wall_received` (`uid`,`wall`,`received`),
INDEX `private_wall_origin_commented` (`private`,`wall`,`origin`,`commented`) INDEX `private_wall_origin_commented` (`private`,`wall`,`origin`,`commented`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data'; ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data';

View file

@ -29,6 +29,7 @@ use Friendica\Util\Security;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Friendica\Util\XML; use Friendica\Util\XML;
use Friendica\Worker\Delivery; use Friendica\Worker\Delivery;
use Friendica\Protocol\ActivityPub;
use Text_LanguageDetect; use Text_LanguageDetect;
class Item extends BaseObject class Item extends BaseObject
@ -3575,4 +3576,69 @@ class Item extends BaseObject
return Contact::isForum($item['contact-id']); return Contact::isForum($item['contact-id']);
} }
/**
* Search item id for given URI or plink
*
* @param string $uri
* @param integer $uid
*
* @return integer item id
*/
public static function searchByLink($uri, $uid = 0)
{
$ssl_uri = str_replace('http://', 'https://', $uri);
$uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
$item = DBA::selectFirst('item', ['id'], ['uri' => $uris, 'uid' => $uid]);
if (DBA::isResult($item)) {
return $item['id'];
}
$itemcontent = DBA::selectFirst('item-content', ['uri-id'], ['plink' => $uris]);
if (!DBA::isResult($itemcontent)) {
return 0;
}
$itemuri = DBA::selectFirst('item-uri', ['uri'], ['id' => $itemcontent['uri-id']]);
if (!DBA::isResult($itemuri)) {
return 0;
}
$item = DBA::selectFirst('item', ['id'], ['uri' => $itemuri['uri'], 'uid' => $uid]);
if (DBA::isResult($item)) {
return $item['id'];
}
return 0;
}
/**
* Fetches item for given URI or plink
*
* @param string $uri
* @param integer $uid
*
* @return integer item id
*/
public static function fetchByLink($uri, $uid = 0)
{
$item_id = self::searchByLink($uri, $uid);
if (!empty($item_id)) {
echo "a\n";
return $item_id;
}
echo "b\n";
ActivityPub\Processor::fetchMissingActivity($uri);
$item_id = self::searchByLink($uri, $uid);
if (!empty($item_id)) {
echo "c\n";
return $item_id;
}
echo "d\n";
return 0;
}
} }

View file

@ -34,7 +34,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1318); define('DB_UPDATE_VERSION', 1319);
} }
return [ return [
@ -736,6 +736,7 @@ return [
"PRIMARY" => ["id"], "PRIMARY" => ["id"],
"uri-plink-hash" => ["UNIQUE", "uri-plink-hash"], "uri-plink-hash" => ["UNIQUE", "uri-plink-hash"],
"uri" => ["uri(191)"], "uri" => ["uri(191)"],
"plink" => ["plink(191)"],
"uri-id" => ["uri-id"] "uri-id" => ["uri-id"]
] ]
], ],