On Mittwoch 28 Januar 2009 03:55:30 Loui Chang wrote:
> On Sun, Jan 25, 2009 at 07:39:26PM +0100, Lukas Appelhans wrote:
> > The reason why I need to get all packages is to build a list of available
> > packages (which gets cached then...), the user can search in it then...
> > (or just dig a bit in it...). This all is for the AUR-Intergration into
> > Shaman2 (you might probably already know the 1.x version which is in
> > community...)...
>
> Alright. That's not so bad, but we'd have to make sure this is
> aggressively cached on the server side as well to prevent abuse.
> Updating only every 12 to 24 hours.
Ok :) I attached a patch, which makes update it every 24 Hours (first call
after new day... ;))...
Untested though (as usual) ;)
Comments?
Lukas
diff --git a/web/html/rpc.php b/web/html/rpc.php
index 033cba5..d58a487 100644
--- a/web/html/rpc.php
+++ b/web/html/rpc.php
@@ -19,6 +19,7 @@ if ( $_SERVER['REQUEST_METHOD'] == 'GET' ) {
echo '<ul>';
echo '<li>search</li>';
echo '<li>info</li>';
+ echo '<li>all_packages</li>';
echo '</ul><br />';
echo 'Each method requires the following HTTP GET syntax:<br />';
echo ' type=<i>methodname</i>&arg=<i>data</i> <br /><br />';
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index 81c0831..ca44d95 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -21,9 +21,11 @@ if (!extension_loaded('json'))
**/
class AurJSON {
private $dbh = false;
- private $exposed_methods = array('search','info');
+ private $exposed_methods = array('search','info','all_packages');
private $fields = array('ID','Name','Version','CategoryID','Description',
'URL','URLPath','License','NumVotes','OutOfDate');
+ private $all_packages = array();
+ private $last_checked = 0;
/**
* Handles post data, and routes the request.
@@ -147,5 +149,32 @@ class AurJSON {
return $this->json_error('No result found');
}
}
+
+ /**
+ * Returns all packages
+ */
+ private function all_packages() {
+ if (date('Ymd') > $last_checked) {
+ $last_checked = date('Ymd');
+ $query = "SELECT " . implode(',', $this->fields) .
+ " FROM Packages WHERE DummyPkg=0 ";
+
+ $result = db_query($query, $this->dbh);
+
+ if ( $result && (mysql_num_rows($result) > 0) ) {
+ $search_data = array();
+ while ( $row = mysql_fetch_assoc($result) ) {
+ array_push($search_data, $row);
+ }
+
+ mysql_free_result($result);
+ $all_packages = $search_data;
+ }
+ return $this->json_results('all_packages', $all_packages);
+ }
+ else {
+ return $this->json_error('No results found');
+ }
+ }
}