src/hg/lib/hdb.c 1.398
1.398 2009/03/17 05:56:38 hiram
Remember answers to hDbIsActive and hgDbExists, was being called thousands of times during a simple refresh
Index: src/hg/lib/hdb.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/hdb.c,v
retrieving revision 1.397
retrieving revision 1.398
diff -b -B -U 4 -r1.397 -r1.398
--- src/hg/lib/hdb.c 17 Mar 2009 04:24:28 -0000 1.397
+++ src/hg/lib/hdb.c 17 Mar 2009 05:56:38 -0000 1.398
@@ -267,30 +267,54 @@
/*
Function to check if this is a valid db name
*/
{
+static struct hash *dbsChecked = NULL;
+
+if (dbsChecked)
+ {
+ void *hashDb = hashFindVal(dbsChecked, database);
+ if (hashDb)
+ return(hashIntVal(dbsChecked, database));
+ }
+else
+ dbsChecked = newHash(0);
+
struct sqlConnection *conn = hConnectCentral();
char buf[128];
char query[256];
boolean res = FALSE;
safef(query, sizeof(query), "select name from dbDb where name = '%s'",
database);
res = (sqlQuickQuery(conn, query, buf, sizeof(buf)) != NULL);
hDisconnectCentral(&conn);
+hashAddInt(dbsChecked, database, res);
return res;
}
boolean hDbIsActive(char *database)
/* Function to check if this is a valid and active db name */
{
+static struct hash *dbsChecked = NULL;
+
+if (dbsChecked)
+ {
+ void *hashDb = hashFindVal(dbsChecked, database);
+ if (hashDb)
+ return(hashIntVal(dbsChecked, database));
+ }
+else
+ dbsChecked = newHash(0);
+
struct sqlConnection *conn = hConnectCentral();
char buf[128];
char query[256];
boolean res = FALSE;
safef(query, sizeof(query),
"select name from dbDb where name = '%s' and active = 1", database);
res = (sqlQuickQuery(conn, query, buf, sizeof(buf)) != NULL);
hDisconnectCentral(&conn);
+hashAddInt(dbsChecked, database, res);
return res;
}
char *hDefaultDbForGenome(char *genome)