소스 검색

Fetch items by given uri

pull/7404/head
Michael 2 달 전
부모
커밋
41a1c1c3e6
3개의 변경된 파일77개의 추가작업 그리고 8개의 파일을 삭제
  1. 9
    7
      database.sql
  2. 66
    0
      src/Model/Item.php
  3. 2
    1
      static/dbstructure.config.php

+ 9
- 7
database.sql 파일 보기

@@ -1,6 +1,6 @@
1 1
 -- ------------------------------------------
2 2
 -- Friendica 2019.09-dev (Dalmatian Bellflower)
3
+-- DB_UPDATE_VERSION 1319
3 4
 -- ------------------------------------------
4 5
 
5 6
 
@@ -605,15 +605,15 @@ CREATE TABLE IF NOT EXISTS `item` (
605 605
 	 INDEX `extid` (`extid`(191)),
606 606
 	 INDEX `uid_id` (`uid`,`id`),
607 607
 	 INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`),
608
-	 INDEX `uid_created` (`uid`,`created`),
608
+	 INDEX `uid_received` (`uid`,`received`),
609 609
 	 INDEX `uid_commented` (`uid`,`commented`),
610 610
 	 INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
611 611
 	 INDEX `uid_network_received` (`uid`,`network`,`received`),
612 612
 	 INDEX `uid_network_commented` (`uid`,`network`,`commented`),
613 613
 	 INDEX `uid_thrparent` (`uid`,`thr-parent`(190)),
614 614
 	 INDEX `uid_parenturi` (`uid`,`parent-uri`(190)),
615
-	 INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`),
616
-	 INDEX `authorid_created` (`author-id`,`created`),
615
+	 INDEX `uid_contactid_received` (`uid`,`contact-id`,`received`),
616
+	 INDEX `authorid_received` (`author-id`,`received`),
617 617
 	 INDEX `ownerid` (`owner-id`),
618 618
 	 INDEX `contact-id` (`contact-id`),
619 619
 	 INDEX `uid_uri` (`uid`,`uri`(190)),
@@ -667,6 +667,7 @@ CREATE TABLE IF NOT EXISTS `item-content` (
667 667
 	 PRIMARY KEY(`id`),
668 668
 	 UNIQUE INDEX `uri-plink-hash` (`uri-plink-hash`),
669 669
 	 INDEX `uri` (`uri`(191)),
670
+	 INDEX `plink` (`plink`(191)),
670 671
 	 INDEX `uri-id` (`uri-id`)
671 672
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Content for all posts';
672 673
 
@@ -1157,15 +1158,15 @@ CREATE TABLE IF NOT EXISTS `thread` (
1157 1158
 	`bookmark` boolean COMMENT '',
1158 1159
 	 PRIMARY KEY(`iid`),
1159 1160
 	 INDEX `uid_network_commented` (`uid`,`network`,`commented`),
1160
-	 INDEX `uid_network_created` (`uid`,`network`,`created`),
1161
+	 INDEX `uid_network_received` (`uid`,`network`,`received`),
1161 1162
 	 INDEX `uid_contactid_commented` (`uid`,`contact-id`,`commented`),
1162
-	 INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`),
1163
+	 INDEX `uid_contactid_received` (`uid`,`contact-id`,`received`),
1163 1164
 	 INDEX `contactid` (`contact-id`),
1164 1165
 	 INDEX `ownerid` (`owner-id`),
1165 1166
 	 INDEX `authorid` (`author-id`),
1166
-	 INDEX `uid_created` (`uid`,`created`),
1167
+	 INDEX `uid_received` (`uid`,`received`),
1167 1168
 	 INDEX `uid_commented` (`uid`,`commented`),
1168
-	 INDEX `uid_wall_created` (`uid`,`wall`,`created`),
1169
+	 INDEX `uid_wall_received` (`uid`,`wall`,`received`),
1169 1170
 	 INDEX `private_wall_origin_commented` (`private`,`wall`,`origin`,`commented`)
1170 1171
 ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data';
1171 1172
 

+ 66
- 0
src/Model/Item.php 파일 보기

@@ -29,6 +29,7 @@ use Friendica\Util\Security;
29 29
 use Friendica\Util\Strings;
30 30
 use Friendica\Util\XML;
31 31
 use Friendica\Worker\Delivery;
32
+use Friendica\Protocol\ActivityPub;
32 33
 use Text_LanguageDetect;
33 34
 
34 35
 class Item extends BaseObject
@@ -3575,4 +3576,69 @@ class Item extends BaseObject
3575 3576
 
3576 3577
 		return Contact::isForum($item['contact-id']);
3577 3578
 	}
3579
+
3580
+	/**
3581
+	 * Search item id for given URI or plink
3582
+	 *
3583
+	 * @param string $uri
3584
+	 * @param integer $uid
3585
+	 *
3586
+	 * @return integer item id
3587
+	 */
3588
+	public static function searchByLink($uri, $uid = 0)
3589
+	{
3590
+		$ssl_uri = str_replace('http://', 'https://', $uri);
3591
+		$uris = [$uri, $ssl_uri, Strings::normaliseLink($uri)];
3592
+
3593
+		$item = DBA::selectFirst('item', ['id'], ['uri' => $uris, 'uid' => $uid]);
3594
+		if (DBA::isResult($item)) {
3595
+			return $item['id'];
3596
+		}
3597
+
3598
+		$itemcontent = DBA::selectFirst('item-content', ['uri-id'], ['plink' => $uris]);
3599
+		if (!DBA::isResult($itemcontent)) {
3600
+			return 0;
3601
+		}
3602
+
3603
+		$itemuri = DBA::selectFirst('item-uri', ['uri'], ['id' => $itemcontent['uri-id']]);
3604
+		if (!DBA::isResult($itemuri)) {
3605
+			return 0;
3606
+		}
3607
+
3608
+		$item = DBA::selectFirst('item', ['id'], ['uri' => $itemuri['uri'], 'uid' => $uid]);
3609
+		if (DBA::isResult($item)) {
3610
+			return $item['id'];
3611
+		}
3612
+
3613
+		return 0;
3614
+	}
3615
+
3616
+	/**
3617
+	 * Fetches item for given URI or plink
3618
+	 *
3619
+	 * @param string $uri
3620
+	 * @param integer $uid
3621
+	 *
3622
+	 * @return integer item id
3623
+	 */
3624
+	public static function fetchByLink($uri, $uid = 0)
3625
+	{
3626
+		$item_id = self::searchByLink($uri, $uid);
3627
+		if (!empty($item_id)) {
3628
+echo "a\n";
3629
+			return $item_id;
3630
+		}
3631
+
3632
+echo "b\n";
3633
+		ActivityPub\Processor::fetchMissingActivity($uri);
3634
+
3635
+		$item_id = self::searchByLink($uri, $uid);
3636
+		if (!empty($item_id)) {
3637
+echo "c\n";
3638
+			return $item_id;
3639
+		}
3640
+
3641
+echo "d\n";
3642
+		return 0;
3643
+	}
3578 3644
 }

+ 2
- 1
static/dbstructure.config.php 파일 보기

@@ -34,7 +34,7 @@
34 34
 use Friendica\Database\DBA;
35 35
 
36 36
 if (!defined('DB_UPDATE_VERSION')) {
37
-	define('DB_UPDATE_VERSION', 1318);
37
+	define('DB_UPDATE_VERSION', 1319);
38 38
 }
39 39
 
40 40
 return [
@@ -736,6 +736,7 @@ return [
736 736
 			"PRIMARY" => ["id"],
737 737
 			"uri-plink-hash" => ["UNIQUE", "uri-plink-hash"],
738 738
 			"uri" => ["uri(191)"],
739
+			"plink" => ["plink(191)"],
739 740
 			"uri-id" => ["uri-id"]
740 741
 		]
741 742
 	],

Loading…
취소
저장