ä»æ¥ãTwitterã¯é 延ãã¦ããã§ããã®é 延ãèµ·ãããããªTwitterã®ã¢ã¼ããã¯ãã£ãèãã¦ã¿ãããTwitterã®ä¸å ·åããèãã¦ã¿ãã ãã§ãå®å ¨ã«æ³åã§ãã£ã¦ãå®éã«ãªã«ãã®è³æã«åºã¥ãããã¯ãã¦ãªãã®ã§ã念ã®ããã
ã¾ãããµã¼ãã¼æ§æã¯ãããªæãã
Webãµã¼ãã¼ã¨ãã¼ã¿ãã¼ã¹ãµã¼ãã¼ã¯å½ç¶ã¨ãã¦ãæ稿ããã¨ãã®å¦çã管çããããã®ã¡ãã»ã¼ã¸ãã¥ã¼ã¨ã¦ã¼ã¶ã¼ããããã¼ã¸ãä¿åãã¦ãããã£ãã·ã¥ãããã¨æãã
ã¡ãªã¿ã«ãã®ã¡ãã»ã¼ã¸ãã¥ã¼ã¯ä»ã¾ã§Rubyã§æ¸ããã¦ãããã®ãScalaã«æ¸ãç´ãããããããTwitter Kestrel Projectã¨ãã¦ã½ã¼ã¹ãå
¬éããã¦ãã
Twitter message queues move to Scala | The Scala Programming Language
ã§ããã¼ã¿ãã¼ã¹ã
ã¦ã¼ã¶ã¼ãã¼ãã«ã¨ã¹ãã¼ã¿ã¹ãã¼ãã«ã¯ãã¡ããå¿
è¦ã
ãã¨ã¯ãã¦ã¼ã¶ã¼ã®ã¿ã¤ã ã©ã¤ã³ã管çãããã¼ãã«ã¨ãªãã©ã¤ã管çãããã¼ãã«ãããã
ããã¨ããã©ãã¼ã管çãããã¼ãã«ã
追è¨(2009/3/5 11:36):ã¿ã¤ã ã©ã¤ã³ãã¼ãã«ã¯ãã¿ã¤ã ã©ã¤ã³ã40ãã¼ã¸ã¾ã§ããè¦ããªããã¨ããã1ã¦ã¼ã¶ã¼ããã40Ã20=800件ç¨åº¦ãé度ã«åãæ¨ã¦ã¦ãã¨æããã¾ãã
ããããã¨ãæ稿ã®ã¨ãã®å¦çã¯ãããªæãã«ãªãã
é
延ãèµ·ãã¦ããèªåã®ã¿ã¤ã ã©ã¤ã³ã¨ãããªãå®ã®ã¤ã¶ãããã«ã¯è¡¨ç¤ºãããã®ã§ããã®å¦çã¯æ稿æã«è¡ãããã¯ãã
æ¬ä¼¼ã³ã¼ãã§å¦çãæ¸ãã¦ã¿ãã
/** æ稿å¦ç * @param id æ稿è ã®id * @param status æ稿å 容 */ function post(String $id, String $status){ $statusId = getSequence(); //ã¹ãã¼ã¿ã¹è¿½å insert into ã¹ãã¼ã¿ã¹(ã¹ãã¼ã¿ã¹ID, çºè¨å 容, ã¦ã¼ã¶ã¼ID, çºè¨æé) values ($statusId, $status, $id, now()); //ãªãã©ã¤è¿½å if($status.startWith("@")){ $repliesId = getReply($status); insert into ãªãã©ã¤(ã¦ã¼ã¶ã¼ID, ã¹ãã¼ã¿ã¹ID) values($repliesId, $statusId); } //èªåã®ã¿ã¤ã ã©ã¤ã³ã«è¿½å insert into ã¿ã¤ã ã©ã¤ã³(ã¦ã¼ã¶ã¼ID, ã¹ãã¼ã¿ã¹ID) values($id, $statusId); //ã¡ãã»ã¼ã¸ãã¥ã¼ã«è¿½å $queue.send($id, $statusId); //ãã£ãã·ã¥ãã¯ãªã¢ $cache.clear($id); }
ãã®ãã¨ãã¡ãã»ã¼ã¸ãã¥ã¼ã®å¦çã¨ãã¦åãã©ãã¯ã¼ã®ã¿ã¤ã ã©ã¤ã³ã«è¿½å ããããã®å¦çã¯æ稿å¦çã¨ã¯éåæã«å¼ã³åºããã¦ãä¸ã¤ãã¤å¦çããã¦ããã
æ稿æã®å¦çãããæ稿è
IDã¨ã¹ãã¼ã¿ã¹IDã渡ã£ã¦ãããã¹ãã¼ã¿ã¹ããæ稿è
ãå¾ããã¨ã¯æããã©ããã¼ã¿ãã¼ã¹å¼ã³åºããæ¸ããããã®ã§æ稿è
IDã渡ãããã¨æãã
ãã®å¦çãçµæ§éãã¦ãæç¨¿é »åº¦ã«å¯¾ãã¦ããã©ãã¯ã¼ã®ã¿ã¤ã ã©ã¤ã³ã¸è¿½å ããå¦çãæ»ã£ã¦ããã¨ãé
延ãçºçããã¨ããããã ã
ãããæ¬ä¼¼ã³ã¼ãã§æ¸ãã¦ã¿ãã
/** ã¡ãã»ã¼ã¸å¦ç * @param id æ稿è ID * @param statusId æ稿 */ function onMessage($id, $statusId){ //ãã©ãã¯ã¼ãæ½åº select * into $followers from ãã©ãã¼ where ãã©ãã¼å ID=$id; //åãã©ãã¯ã¼ã®ã¿ã¤ã ã©ã¤ã³ã«è¿½å foreach($follower in $followers){ insert into ã¿ã¤ã ã©ã¤ã³(ã¦ã¼ã¶ã¼ID, ã¹ãã¼ã¿ã¹ID) values($follower.ã¦ã¼ã¶ã¼ID, $statusId); $cache.clear($follower.ã¦ã¼ã¶ã¼ID); } }
ã¤ãã§ã«ãããããã¼ã¸è¡¨ç¤ºã¯ãããªæãã®å¦çã«ãªãã
/** ããããã¼ã¸è¡¨ç¤º * @param id ã¦ã¼ã¶ã¼ID */ function topPage(String $id){ //ãã£ãã·ã¥ã«ããã°ãã£ãã·ã¥ãã表示 if($cache.exists($id)){ print($cache.get($id)); return; } //ã¿ã¤ã ã©ã¤ã³æ½åº select ã¦ã¼ã¶ã¼.ã¦ã¼ã¶ã¼å, ã¹ãã¼ã¿ã¹.çºè¨å 容 into $timeline from ã¿ã¤ã ã©ã¤ã³ inner join ã¹ãã¼ã¿ã¹ on ã¿ã¤ã ã©ã¤ã³.ã¹ãã¼ã¿ã¹ID=ã¹ãã¼ã¿ã¹.ã¹ãã¼ã¿ã¹ID inner join ã¦ã¼ã¶ã¼ on ã¹ãã¼ã¿ã¹.ã¦ã¼ã¶ã¼ID=ã¦ã¼ã¶ã¼.ã¦ã¼ã¶ã¼ID where ã¿ã¤ã ã©ã¤ã³.ã¦ã¼ã¶ã¼ID=$id order by çºè¨æé desc //表示 $view.clear(); foreach($statusin $timeline){ $view.add($status); } print($view); //ãã£ãã·ã¥ã«è¿½å $cache.add($id, $view); }
ãããªãå®ã®ã¤ã¶ãããã®è¡¨ç¤ºã¯ãã¿ã¤ã ã©ã¤ã³ã®ã¨ãã®ãã£ãã·ã¥ä½¿ããªãçãæ稿æã«ãã¼ã¿è¿½å ããã¦ããã®ã§ãé
延ããªãã
/** ãããªãå®ã®ã¤ã¶ãããã表示 * @param id ã¦ã¼ã¶ã¼ID */ function replies($id){ //ãªãã©ã¤æ½åº select ã¦ã¼ã¶ã¼.ã¦ã¼ã¶ã¼å, ã¹ãã¼ã¿ã¹.çºè¨å 容 into $replies from ãªãã©ã¤ inner join ã¹ãã¼ã¿ã¹ on ãªãã©ã¤.ã¹ãã¼ã¿ã¹ID=ã¹ãã¼ã¿ã¹.ã¹ãã¼ã¿ã¹ID inner join ã¦ã¼ã¶ã¼ on ã¹ãã¼ã¿ã¹.ã¦ã¼ã¶ã¼ID=ã¦ã¼ã¶ã¼.ã¦ã¼ã¶ã¼ID where ãªãã©ã¤.ã¦ã¼ã¶ã¼ID=$id order by ã¹ãã¼ã¿ã¹.çºè¨æé desc //表示 $view.clear(); foreach($statusin $replies){ $view.add($status); } print($view); }
ã¨ãã ããããããªæãã®å¦çãè¡ããã¦ããã®ã§ã¯ãªããã¨æ³åããããã§ãã
ãããããæåããã¢ã¼ããã¯ãã£ãæ¨æ¸¬ããè½åã£ã¦ããã®ã¯ããããã°ã®ã¨ãã«éè¦ã§ããã
ã¡ãªã¿ã«ãä»åã®æ¬ä¼¼ã³ã¼ãã¿ããã«ã³ã¼ãä¸ã«ãã®ã¾ã¾SQLãæ¸ããã°ä¾¿å©ãããã£ã¦æã£ã人ã¯ãid:i-zukaãä½ã£ãalinous coreãè¦ã¦ã¿ãã¨ããã¨æãã¾ãã
ä»åã®æ¬ä¼¼ã³ã¼ãã¯alinous coreã®ä»æ§ã¨ã¯ç¡é¢ä¿ã§ããã©ããããselect * into $aãã®æ¸ãæ¹ã¯alinous coreããåã£ã¦ããã
追è¨(2009/3/5 14:02)
twitter.com/kisãªã©ãã¦ã¼ã¶ã¼ã®ã¿ã¤ã ã©ã¤ã³ãç´æ¥è¦ã«ãã£ãã¨ãã«ã¯ã¹ãã¼ã¿ã¹ãã¼ãã«ããç´æ¥ã¨ã£ã¦ããã¨èãããã¾ããã ãããããé
延ããªãã
ã¤ã¾ããããªæãã
/** ã¦ã¼ã¶ã¼ã®ã¿ã¤ã ã©ã¤ã³ã表示 * @param id ã¦ã¼ã¶ã¼ID */ function userTimeline($id){ //ãªãã©ã¤æ½åº select ã¦ã¼ã¶ã¼.ã¦ã¼ã¶ã¼å, ã¹ãã¼ã¿ã¹.çºè¨å 容 into $timeline from ã¹ãã¼ã¿ã¹ inner join ã¦ã¼ã¶ã¼ on ã¹ãã¼ã¿ã¹.ã¦ã¼ã¶ã¼ID=ã¦ã¼ã¶ã¼.ã¦ã¼ã¶ã¼ID where ã¹ãã¼ã¿ã¹.ã¦ã¼ã¶ã¼ID=$id order by ã¹ãã¼ã¿ã¹.çºè¨æé desc //表示 $view.clear(); foreach($statusin $timeline){ $view.add($status); } print($view); }