{"id":1563,"date":"2016-05-14T17:29:09","date_gmt":"2016-05-14T09:29:09","guid":{"rendered":"https:\/\/www.freemindworld.com\/blog\/?p=1563"},"modified":"2017-06-26T09:34:40","modified_gmt":"2017-06-26T01:34:40","slug":"160514_optimize_synology_photostation","status":"publish","type":"post","link":"https:\/\/www.freemindworld.com\/blog\/2016\/160514_optimize_synology_photostation.shtml","title":{"rendered":"Synology PhotoStation\u6027\u80fd\u4f18\u5316"},"content":{"rendered":"<p><strong>\u672c\u6587\u7684\u5185\u5bb9\u5df2\u7ecf\u8fc7\u65f6\uff0c6.7.0\u4ee5\u4e0a\u7684Photo Station\u5df2\u7ecf\u6ca1\u6709\u4e25\u91cd\u7684\u6027\u80fd\u95ee\u9898\u4e86\u3002<\/strong><\/p>\n<p>\u6211\u6298\u817e\u8fc7\u4e0d\u5c11\u5bb6\u7528NAS\u65b9\u6848\uff0c\u5305\u62ec\u6700\u65e9\u7684<a href=\"https:\/\/www.freemindworld.com\/blog\/2009\/090305_my_book_world_edition_hack.shtml\">WD My Book World Edition<\/a>\uff0c\u540e\u6765\u7684<a href=\"https:\/\/www.freemindworld.com\/blog\/2010\/101121_o2_joggler.shtml\">Joggler<\/a>\uff0c\u518d\u5230\u540e\u6765\u7684Raspberry Pi\uff0c\u8fd9\u4e9b\u65b9\u6848\u9664\u4e86\u6027\u80fd\u5b58\u5728\u4e00\u4e9b\u95ee\u9898\u4ee5\u5916\uff0c\u6700\u5927\u7684\u7f3a\u70b9\u5c31\u662f\u6613\u7528\u6027\u5b58\u5728\u95ee\u9898\uff0c\u4e0d\u4f46\u975e\u201c\u4e13\u4e1a\u201d\u4eba\u58eb\u7528\u8d77\u6765\u5b58\u5728\u56f0\u96be\uff0c\u5c31\u8fde\u6211\u81ea\u5df1\u4e5f\u5bf9\u571f\u6cd5\u6ce1\u5236\u7684\u7167\u7247\u7ba1\u7406\u529f\u80fd\u611f\u5230\u4e0d\u6ee1\u3002\u76f4\u5230\u4e24\u5e74\u524d\u5165\u4e86<a href=\"http:\/\/www.synology.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u7fa4\u6656<\/a>\uff08Synology\uff09\u7684\u5bb6\u7528NAS DS214play\uff0c\u4e8b\u60c5\u624d\u53d8\u5f97\u5b89\u9038\u8d77\u6765\u3002<\/p>\n<p>\u5e73\u5fc3\u800c\u8bba\uff0cSynology\u7684\u7cfb\u7edf\u867d\u7136\u529f\u80fd\u5f3a\u5927\uff0c\u4f53\u9a8c\u4e5f\u8fd8\u4e0d\u9519\uff0c\u4f46\u7ec6\u8282\u4e0a\u505a\u5f97\u5176\u5b9e\u771f\u662f\u633a\u7cd9\u7684\u3002\u6700\u8fd1\u5c31\u53d1\u73b0\u4e86\u5b83\u7684\u7167\u7247\u7ba1\u7406\u8f6f\u4ef6PhotoStation\u51fa\u73b0\u4e86\u4e25\u91cd\u7684\u6027\u80fd\u95ee\u9898\uff0c\u5728\u7167\u7247\u5e93\u91cc\u53ea\u5b58\u4e868\u4e07\u4f59\u5f20\u7167\u7247\u7684\u60c5\u51b5\u4e0b\uff0c\u6253\u5f00\u9996\u9875\u8981\u82b1\u8d39\u7684\u65f6\u95f4\u5df2\u7ecf\u8d85\u8fc7\u4e8620\u79d2\uff0c\u6bcf\u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\u5939\u90fd\u9700\u8981\u7b49\u5f8510\u79d2\u4ee5\u4e0a\uff0c\u51e0\u4e4e\u4e0d\u53ef\u7528\u4e86\u3002<\/p>\n<p>\u4ee5\u4e0b\u5206\u6790\u4ee5DSM 6.0\u4e3a\u4f8b\uff0cPhotoStation\u7248\u672c\u4e3a6.4-3166\u3002PhotoStation\u7684\u5b89\u88c5\u8def\u5f84\u4e3a\/volume1\/@appstore\/PhotoStation\u3002<\/p>\n<p>Synology\u7684<a href=\"https:\/\/www.synology.cn\/en-global\/dsm\/6.0\/features\" target=\"_blank\" rel=\"noopener noreferrer\">DSM<\/a>\u7cfb\u7edf\uff0c\u540e\u53f0\u4f7f\u7528<a href=\"http:\/\/www.postgresql.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">PostgreSQL<\/a>\u6570\u636e\u5e93\uff0c\u524d\u7aef\u662fPHP\u9875\u9762\u3002\u7b80\u5355\u63a8\u7406\u4e00\u4e0b\u5c31\u53ef\u4ee5\u77e5\u9053\uff0cPhotoStation\u7684\u6027\u80fd\u74f6\u9888\u4e3b\u8981\u662f\u5728\u5bf9\u7167\u7247\u7d22\u5f15\u6570\u636e\u5e93\u7684\u8bbf\u95ee\u4e0a\u3002\u6027\u80fd\u8c03\u4f18\u7684\u7b2c\u4e00\u6b65\u5c31\u662f\u5148\u8981\u627e\u5230\u54ea\u4e9bSQL\u67e5\u8be2\u5360\u7528\u4e86\u592a\u591a\u7684\u65f6\u95f4\u3002\u6253\u5f00PostgreSQL\u8bb0\u5f55SQL\u67e5\u8be2\u7684\u5f00\u5173\uff0c\u5e76\u67e5\u770b\u6240\u6709SQL\u6267\u884c\u60c5\u51b5\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">$ sudo su postgres\r\n$ vi ~\/postgresql.conf\r\nlog_statement = 'all'\r\n$ psql photo postgres\r\n# SELECT pg_reload_conf();\r\n# \\q\r\n$ exit\r\n$ sudo tail -f \/var\/log\/postgresql.log<\/pre>\n<p>\u901a\u8fc7\u67e5\u770bSQL\u6267\u884c\u8bb0\u5f55\uff0c\u5f88\u5bb9\u6613\u53d1\u73b0\u51e0\u4e2a\u660e\u663e\u7684\u6162\u67e5\u8be2\uff1a<\/p>\n<p>1.<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">SELECT COUNT(*) as total FROM photo_image; \r\nSELECT COUNT(*) as total FROM video;<\/pre>\n<p>2.<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">SELECT COUNT(logid), MAX(logid) FROM photo_log;<\/pre>\n<p>3.<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">SELECT * FROM (\r\n    SELECT path AS filename, timetaken AS takendate, \r\n        create_time AS createdate, 'photo' AS type\r\n    FROM photo_image\r\n    WHERE path LIKE '\/volume1\/photo\/%'\r\n        AND path NOT LIKE '\/volume1\/photo\/%\/%' AND disabled = 'f'\r\n    UNION\r\n    SELECT path AS filename, mdate AS takendate,\r\n        date AS createdate, 'video' AS type\r\n    FROM video\r\n    WHERE path LIKE '\/volume1\/photo\/%'\r\n        AND path NOT LIKE '\/volume1\/photo\/%\/%'\r\n        AND disabled = 'f'\r\n    ) AS totalCount; <\/pre>\n<p>4.<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">SELECT path, resolutionx, resolutiony, version FROM (\r\n    SELECT path, resolutionx, resolutiony, version,\r\n        create_time, privilege_shareid, disabled\r\n    FROM photo_image WHERE privilege_shareid IN (\r\n        SELECT shareid FROM photo_share WHERE ref_shareid = (\r\n            SELECT shareid FROM photo_share WHERE sharename = '2016'))\r\n    AND disabled = 'f'\r\n    UNION ALL\r\n    SELECT path, resolutionx, resolutiony, 0 AS version, \r\n        date AS create_time, privilege_shareid, disabled\r\n    FROM video WHERE privilege_shareid IN (\r\n        SELECT shareid FROM photo_share WHERE ref_shareid = (\r\n            SELECT shareid FROM photo_share WHERE sharename = '2016'))\r\n    AND disabled = 'f') temp\r\nORDER BY create_time DESC LIMIT 1; <\/pre>\n<p>\u4f18\u5316\u7684\u601d\u8def\u5f88\u7b80\u5355\uff0c\u7531\u4e8ePhotoStation\u5728\u6b63\u5e38\u60c5\u51b5\u4e0b\u8bbf\u95ee\u6570\u636e\u5e93\u6240\u9700\u8981\u7684\u8bfb\u6027\u80fd\u662f\u8fdc\u8fdc\u5927\u4e8e\u5199\u6027\u80fd\u7684\uff0c\u6240\u4ee5\u5c31\u901a\u8fc7\u727a\u7272\u5199\u6027\u80fd\u6765\u9010\u4e00\u51fb\u7834\u4e0a\u9762\u8fd9\u4e9b\u6162\u67e5\u8be2\uff1a<\/p>\n<p>1. \u7a0b\u5e8f\u7684\u76ee\u7684\u5c31\u662f\u60f3\u77e5\u9053\u7cfb\u7edf\u4e2d\u6709\u591a\u5c11\u5f20\u7167\u7247\u548c\u591a\u5c11\u4e2a\u89c6\u9891\uff08\u800c\u4e14\u5176\u5b9e\u5e76\u4e0d\u9700\u8981\u7cbe\u786e\u77e5\u9053\uff0c\u5dee\u4e0d\u591a\u5c31\u884c\uff09\uff0c\u53ef\u60dc\u5bf9\u4e8ePostgreSQL\u6765\u8bf4\uff0c\u7531\u4e8e\u5b83\u91c7\u7528<a href=\"https:\/\/wiki.postgresql.org\/wiki\/MVCC\" target=\"_blank\" rel=\"noopener noreferrer\">MVCC<\/a>\u6765\u89e3\u51b3\u5e76\u53d1\u95ee\u9898\uff0cSELECT COUNT(*)\u662f\u4e00\u4e2a\u9700\u8981\u8fdb\u884c\u5168\u8868\u626b\u63cf\u7684\u6162\u64cd\u4f5c\u3002\u89e3\u51b3\u65b9\u6848\u5c31\u662f\u7528\u53e6\u5916\u7528\u4e00\u5f20\u8868\u6765\u5b58\u8fd9\u4e24\u4e2a\u8868\u7684\u603b\u8bb0\u5f55\u6761\u6570\uff0c\u5e76\u5728\u539f\u8868\u4e0a\u6dfb\u52a0\u89e6\u53d1\u5668\u6765\u66f4\u65b0\u8bb0\u5f55\u6570\u3002<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nCREATE TABLE photo_count (table_oid Oid PRIMARY KEY, count int);\r\nALTER\u00a0TABLE\u00a0photo_count OWNER\u00a0TO &quot;PhotoStation&quot;;\r\nCREATE FUNCTION count_increment() RETURNS TRIGGER AS $_$\r\nBEGIN\r\n  UPDATE photo_count SET count = count + 1 WHERE table_oid = TG_RELID;\r\n  RETURN NEW;\r\nEND $_$ LANGUAGE 'plpgsql';\r\nCREATE FUNCTION count_decrement() RETURNS TRIGGER AS $_$\r\nBEGIN\r\n  UPDATE photo_count SET count = count - 1\u00a0 WHERE table_oid = TG_RELID;\r\n  RETURN NEW;\r\nEND $_$ LANGUAGE 'plpgsql';\r\nCREATE TRIGGER photo_image_increment_trig AFTER INSERT ON photo_image \r\n  FOR EACH ROW EXECUTE PROCEDURE count_increment();\r\nCREATE TRIGGER photo_image_decrement_trig AFTER DELETE ON photo_image \r\n  FOR EACH ROW EXECUTE PROCEDURE count_decrement();\r\nCREATE TRIGGER video_increment_trig AFTER INSERT ON video \r\n  FOR EACH ROW EXECUTE PROCEDURE count_increment();\r\nCREATE TRIGGER video_decrement_trig AFTER DELETE ON video \r\n  FOR EACH ROW EXECUTE PROCEDURE count_decrement();\r\nINSERT INTO photo_count VALUES \r\n  ('photo_image'::regclass, (SELECT\u00a0COUNT(*) FROM\u00a0photo_count));\r\nINSERT INTO photo_count VALUES \r\n  ('video'::regclass, (SELECT\u00a0COUNT(*) FROM\u00a0video));\r\n<\/pre>\n<p>\u7136\u540e\u5728PHP\u7a0b\u5e8f\u4e2d\u4fee\u6539\u9700\u8981\u7edf\u8ba1\u8868\u6570\u8bb0\u5f55\u6570\u7684\u903b\u8f91\uff0c\u5728\u8fd9\u91cc\u53ef\u4ee5\u770b\u5230\u4f3c\u4e4e\u540c\u4e00\u4e2aSession\u4e2d\u53ea\u4f1a\u67e5\u4e00\u6b21\uff0c\u4f46\u5373\u4f7f\u5c31\u662f\u8fd9\u4e00\u6b21\uff0c\u4e5f\u5df2\u7ecf\u6162\u5f97\u8ba9\u4eba\u4e0d\u5f00\u5fc3\u4e86\uff1a<\/p>\n<pre class=\"brush: diff; title: ; notranslate\" title=\"\">\r\ndiff --git a\/photo\/include\/file.php b\/photo\/include\/file.php\r\nindex 541c5cb..7caa5de 100755\r\n--- a\/photo\/include\/file.php\r\n+++ b\/photo\/include\/file.php\r\n@@ -536,8 +536,11 @@ class File {\r\n \t\tif ($key &amp;&amp; isset($_SESSION&#x5B;SYNOPHOTO_ADMIN_USER]&#x5B;$key])) {\r\n \t\t\treturn $_SESSION&#x5B;SYNOPHOTO_ADMIN_USER]&#x5B;$key];\r\n \t\t}\r\n-\t\t$query = &quot;SELECT count(*) as total FROM $table&quot;;\r\n-\r\n+\t\tif ('photo_image' == $table || 'video' == $table) {\r\n+\t\t\t$query = &quot;SELECT count as total FROM photo_count where table_oid='$table'::regclass&quot;;\r\n+\t\t} else {\r\n+\t\t    $query = &quot;SELECT count(*) as total FROM $table&quot;;\r\n+\t\t}\r\n \t\t$result = PHOTO_DB_Query($query);\r\n \t\tif (!$result) {\r\n \t\t\t\/\/ db query fail, won't update session value\r\n<\/pre>\n<p>2. \u5176\u5b9e\u53ef\u4ee5\u7528\u8ddf\u524d\u4e00\u4e2a\u95ee\u9898\u7c7b\u4f3c\u7684\u65b9\u6cd5\u53bb\u89e3\u51b3\u3002\u4f46\u662f\u8fd9\u4e2a\u5176\u5b9e\u53ea\u662f\u4e00\u4e2a\u6ca1\u592a\u591a\u7528\u5904\u7684\u64cd\u4f5c\u65e5\u5fd7\u8868\uff0c\u6240\u4ee5\u6211\u7528\u66f4\u4e3a\u7b80\u5355\u7c97\u66b4\u7684\u65b9\u6cd5\u53bb\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff1a\u51cf\u5c11\u5728\u6570\u636e\u5e93\u4e2d\u4fdd\u7559\u65e5\u5fd7\u7684\u6761\u6570\u3002\u76f4\u63a5\u4fee\u6539PHP\u7a0b\u5e8f\uff1a<\/p>\n<pre class=\"brush: diff; title: ; notranslate\" title=\"\">\r\ndiff --git a\/photo\/include\/log.php b\/photo\/include\/log.php\r\nindex 1c982af..56385db 100644\r\n--- a\/photo\/include\/log.php\r\n+++ b\/photo\/include\/log.php\r\n@@ -1,8 +1,8 @@\r\n &lt;?php\r\n \r\n class PhotoLog {\r\n-\tconst LIMIT = 100000;\r\n-\tconst PURGECOUNT = 10000;\r\n+\tconst LIMIT = 1000;\r\n+\tconst PURGECOUNT = 100;\r\n \tpublic static $SupportFormat = array(&quot;html&quot;, &quot;csv&quot;);\r\n \r\n \tpublic static function Debug($msg)\r\n<\/pre>\n<p>3. \u7b2c\u4e09\u4e2a\u95ee\u9898\u4e3b\u8981\u4f53\u73b0\u5728\u5bf9\u7167\u7247\u8def\u5f84\u7684\u5904\u7406\u4e0a\uff0c\u4e3a\u4e86\u9009\u51fa\u4f4d\u4e8e\u67d0\u4e2a\u8def\u5f84\u4e0b\uff08\u4e0d\u542b\u5b50\u76ee\u5f55\uff09\u7684\u7167\u7247\uff0c\u7a0b\u5e8f\u91c7\u7528\u4e86path LIKE &#8216;\/path\/%&#8217; AND path NOT LIKE &#8216;\/path\/%\/%&#8217;\u8fd9\u6837\u7684\u67e5\u8be2\u6761\u4ef6\u3002\u5176\u5b9ePostgreSQL\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u662f\u53ef\u4ee5\u5229\u7528path\u5b57\u6bb5\u4e0a\u7684\u7d22\u5f15\u6765\u5f88\u597d\u7684\u4f18\u5316\u8fd9\u4e2a\u67e5\u8be2\u7684\uff0c\u4f46\u662f\u5b9e\u9645\u8fd0\u884c\u4e2d\u53d1\u73b0\uff08\u901a\u8fc7\u5728PostgreSQL\u7684\u5ba2\u6237\u7aef\u4e2d\u7528explain\u548cexplain analyze\u5206\u6790\u67e5\u8be2\uff09\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u7d22\u5f15\u4f1a\u5931\u6548\uff0c\u9020\u6210\u975e\u5e38\u5dee\u7684\u67e5\u8be2\u6027\u80fd\u3002\u89e3\u51b3\u65b9\u6848\u8fd8\u662f\u7528\u5199\u6027\u80fd\u6765\u6362\u8bfb\u6027\u80fd\uff0c\u5148\u5728\u8868\u4e0a\u52a0\u4e00\u4e2adirname\u5b57\u6bb5\u5e76\u5efa\u7acb\u7d22\u5f15\uff0c\u6309path\u7b97\u597d\u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55\u540d\u5199\u5165dirname\uff0c\u7136\u540e\u628a\u67e5\u8be2\u6761\u4ef6\u6539\u4e3a\u5bf9dirname\u7684\u67e5\u8be2\uff0c\u907f\u514d\u4f7f\u7528\u901a\u914d\u7b26\u548cLIKE\u8fd0\u7b97\u5373\u53ef\uff1a<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nALTER TABLE photo_image ADD COLUMN dirname TEXT NOT NULL DEFAULT '';\r\nUPDATE photo_image \r\n    SET dirname = LEFT(path,LENGTH(path)-STRPOS(REVERSE(path),'\/')+1);\r\nALTER TABLE video ADD COLUMN dirname TEXT NOT NULL DEFAULT '';\r\nUPDATE video SET dirname = LEFT(path,LENGTH(path)-STRPOS(REVERSE(path),'\/')+1);\r\nCREATE INDEX dirname_index ON photo_image USING btree(dirname);\r\nCREATE INDEX dirname_index ON video USING btree(dirname);\r\nCREATE OR REPLACE FUNCTION set_dirname()\r\n RETURNS trigger\r\n LANGUAGE plpgsql\r\nAS $function$\r\nBEGIN\r\n  NEW.dirname := LEFT(NEW.path,LENGTH(NEW.path)-STRPOS(REVERSE(NEW.path),'\/')+1);\r\n  RETURN NEW;\r\nEND $function$\r\nCREATE TRIGGER set_dirname_trigger \r\nBEFORE INSERT OR UPDATE ON photo_image \r\nFOR EACH ROW \r\n  EXECUTE PROCEDURE set_dirname();\r\nCREATE TRIGGER set_dirname_trigger \r\nBEFORE INSERT OR UPDATE ON video \r\nFOR EACH ROW \r\n  EXECUTE PROCEDURE set_dirname();\r\n<\/pre>\n<p>\u540c\u65f6\u4fee\u6539PHP\u7a0b\u5e8f\uff1a<\/p>\n<pre class=\"brush: diff; title: ; notranslate\" title=\"\">\r\ndiff --git a\/photo\/include\/photo\/synophoto_csPhotoDB.php b\/photo\/include\/photo\/synophoto_csPhotoDB.php\r\nindex ac8f932..43e58ee 100755\r\n--- a\/photo\/include\/photo\/synophoto_csPhotoDB.php\r\n+++ b\/photo\/include\/photo\/synophoto_csPhotoDB.php\r\n@@ -1607,10 +1607,8 @@ class csSYNOPhotoDB {\r\n \t\t} else {\r\n \t\t\t$albumRealPath = self::EscapeLikeParam(SYNOPHOTO_SERVICE_REAL_DIR_PATH.&quot;{$albumName}\/&quot;);\r\n \t\t}\r\n-\t\t$cond = &quot;path LIKE ? {$this-&gt;escapeStr} AND path NOT LIKE ? {$this-&gt;escapeStr} AND disabled = 'f' &quot;;\r\n-\t\tarray_push($pathSqlParam, &quot;{$albumRealPath}%&quot;);\r\n-\t\tarray_push($pathSqlParam, &quot;{$albumRealPath}%\/%&quot;);\r\n-\r\n+\t\t$cond = &quot;dirname = ? {$this-&gt;escapeStr} AND disabled = 'f' &quot;;\r\n+\t\tarray_push($pathSqlParam, &quot;{$albumRealPath}&quot;);\r\n \t\tif (!$removePhoto) {\r\n \t\t\t$photoQuery = &quot;SELECT path as filename, timetaken as takendate, create_time as createdate, 'photo' as type\r\n FROM photo_image WHERE $cond&quot;;\r\n \t\t\t$sqlParam = array_merge($sqlParam, $pathSqlParam);\r\n<\/pre>\n<p>4. \u8fd9\u4e2a\u67e5\u8be2\u53ea\u662f\u4e3a\u4e86\u67e5\u8be2\u4e00\u4e2a\u76ee\u5f55\u53ca\u5176\u6240\u6709\u5b50\u76ee\u5f55\u4e2d\u6700\u65b0\u4e00\u4e2a\u7167\u7247\u6216\u89c6\u9891\uff0c\u7528\u5176\u7f29\u7565\u56fe\u6765\u4f5c\u4e3a\u76ee\u5f55\u7684\u5c01\u9762\u56fe\u7247\u3002\u7fa4\u6656\u7684\u5de5\u7a0b\u5e08\u81ea\u5df1\u4e5f\u77e5\u9053\u8fd9\u4e2a\u67e5\u8be2\u5f88\u6162\uff0c\u6240\u4ee5\u8fd8\u5728\u7a0b\u5e8f\u4e2d\u52a0\u4e86\u4e2a\u903b\u8f91\uff0c\u5f53\u7167\u7247\u89c6\u9891\u6570\u91cf\u5927\u4e8e200000\u65f6\uff0c\u653e\u5f03\u6309\u65e5\u671f\u6392\u5e8f\uff0c\u76f4\u63a5\u968f\u673a\u9009\u4e00\u5f20\u3002\u7136\u800c\uff0c\u8fd9\u4e2a\u67e5\u8be2\u5b9e\u9645\u4e0a\u662f\u53ef\u4ee5\u7b80\u5355\u4f18\u5316\u7684\uff0c\u660e\u660e\u4e0d\u9700\u8981\u628a\u6240\u6709\u7684\u7167\u7247\u89c6\u9891UNION\u5230\u4e00\u8d77\u540e\u518d\u627e\u51fa\u6700\u65b0\u7684\u4e00\u4e2a\uff0c\u53ef\u4ee5\u76f4\u63a5\u5206\u522b\u627e\u51fa\u6700\u65b0\u7684\u7167\u7247\u548c\u6700\u65b0\u7684\u89c6\u9891\uff0c\u7136\u540e\u518d\u5230\u8fd9\u4e24\u4e2a\u4e2d\u53bb\u53d6\u4e00\u4e2a\u76f8\u5bf9\u66f4\u65b0\u7684\u5c31\u53ef\u4ee5\u4e86\u3002\u76f4\u63a5\u4fee\u6539PHP\u4ee3\u7801\u5b9e\u73b0\uff1a<\/p>\n<pre class=\"brush: diff; title: ; notranslate\" title=\"\">\r\ndiff --git a\/photo\/include\/photo\/synophoto_csPhotoAlbum.php b\/photo\/include\/photo\/synophoto_csPhotoAlbum.php\r\nindex ca128f0..f0e57e7 100755\r\n--- a\/photo\/include\/photo\/synophoto_csPhotoAlbum.php\r\n+++ b\/photo\/include\/photo\/synophoto_csPhotoAlbum.php\r\n@@ -145,9 +145,11 @@ class csSYNOPhotoAlbum {\r\n \t\t$cond .= &quot; AND disabled = 'f'&quot;;\r\n \r\n \t\t$table = &quot;(&quot; .\r\n-\t\t\t\t&quot;SELECT path, resolutionx, resolutiony, version, create_time, privilege_shareid, disabled FROM pho\r\nto_image WHERE $cond &quot; .\r\n+\t\t\t\t&quot;(SELECT path, resolutionx, resolutiony, version, create_time, privilege_shareid, disabled FRO\r\nM photo_image WHERE $cond &quot; .\r\n+\t\t\t\t&quot;ORDER BY create_time DESC LIMIT 1)&quot; .\r\n \t\t\t\t&quot;UNION ALL &quot; .\r\n-\t\t\t\t&quot;SELECT path, resolutionx, resolutiony, 0 as version, date as create_time, privilege_shareid, disa\r\nbled FROM video WHERE $cond &quot; .\r\n+\t\t\t\t&quot;(SELECT path, resolutionx, resolutiony, 0 as version, date as create_time, privilege_shareid,\r\n disabled FROM video WHERE $cond &quot; .\r\n+\t\t\t\t&quot;ORDER BY create_time DESC LIMIT 1)&quot; .\r\n \t\t&quot;) temp&quot;;\r\n \r\n \t\t\/\/ this may cost lots of time, so it won't sort by create_time if the total count exceeds the threshold (200,000)\r\n\r\n<\/pre>\n<p>\u505a\u5b8c\u4ee5\u4e0a\u4f18\u5316\uff0c\u6211\u7684PhotoStation\u5df2\u7ecf\u57fa\u672c\u53ef\u4ee5\u505a\u5230\u70b9\u8fdb\u6587\u4ef6\u5939\u79d2\u5f00\u4e86\uff0c\u81f3\u5c11\u6211\u81ea\u5df1\u5df2\u7ecf\u6bd4\u8f83\u6ee1\u610f\u4e86\u3002\u58f0\u660e\u4e00\u4e0b\uff0c\u5176\u5b9e\u6211\u5e76\u4e0d\u592a\u61c2\u6570\u636e\u5e93\u76f8\u5173\u7406\u8bba\u548c\u6280\u672f\uff0c\u4ee5\u4e0a\u201c\u4f18\u5316\u201d\u53ea\u80fd\u8bf4\u662f\u5728\u6211\u81ea\u5df1\u7684\u5b9e\u9a8c\u4e2d\u8d77\u5230\u4e86\u4f18\u5316\u7684\u6548\u679c\uff0c\u4e5f\u8bb8\u5176\u4e2d\u4e00\u4e9b\u5e76\u4e0d\u592a\u79d1\u5b66\uff0c\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u8d77\u5230\u629b\u7816\u5f15\u7389\u7684\u4f5c\u7528\u3002<\/p>\n<p>\u91cd\u65b0\u5b89\u88c5PhotoStation\u6216\u5347\u7ea7DSM\u7cfb\u7edf\u4f1a\u9020\u6210\u6211\u4eec\u5bf9\u7a0b\u5e8f\u6240\u4f5c\u7684\u4fee\u6539\u4e22\u5931\uff0c\u6240\u4ee5\u5728\u4fee\u6539\u5b8c\u6210\u540e\uff0c\u52a1\u5fc5\u505a\u597d\u5907\u4efd\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u9002\u65f6\u5bf9PostgreSQL\u6570\u636e\u5e93\u8fdb\u884cVACUUM\u64cd\u4f5c\u4f3c\u4e4e\u53ef\u4ee5\u8d77\u5230\u63d0\u9ad8\u8bbf\u95ee\u6027\u80fd\u7684\u76ee\u7684\uff0c\u5c24\u5176\u662f\u5728\u505a\u8fc7\u5927\u91cf\u7167\u7247\u66f4\u65b0\u540e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u7684\u5185\u5bb9\u5df2\u7ecf\u8fc7\u65f6\uff0c6.7.0\u4ee5\u4e0a\u7684Photo Station\u5df2\u7ecf\u6ca1\u6709\u4e25\u91cd\u7684\u6027\u80fd &hellip; <a href=\"https:\/\/www.freemindworld.com\/blog\/2016\/160514_optimize_synology_photostation.shtml\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-1563","post","type-post","status-publish","format-standard","hentry","category-9"],"_links":{"self":[{"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/posts\/1563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/comments?post=1563"}],"version-history":[{"count":18,"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/posts\/1563\/revisions"}],"predecessor-version":[{"id":1645,"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/posts\/1563\/revisions\/1645"}],"wp:attachment":[{"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/media?parent=1563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/categories?post=1563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/tags?post=1563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}