IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24949


Ignore:
Timestamp:
Jul 30, 2009, 4:06:23 PM (17 years ago)
Author:
bills
Message:

to reduce query time get list of nodes to process for each pending magicRun individually

Location:
trunk/ippTools
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/magictool.c

    r24948 r24949  
    804804    // treat limit == 0 as "no limit"
    805805    if (limit) {
    806         psString limitString = psDBGenerateLimitSQL(limit);
     806        // cut limit in half
     807        // hack to prevent pending leaf nodes from blocking branch nodes
     808        psString limitString = psDBGenerateLimitSQL((limit + 1) / 2);
    807809        psStringAppend(&query, " %s", limitString);
    808810        psFree(limitString);
     
    850852
    851853    // look for tree nodes that need to be processed
    852     // XXX: This gets all nodes from all magicRuns that are in 'new'state
    853     // That doens't seem particularly efficient
    854     query = pxDataGet("magictool_toprocess_tree.sql");
     854    query = pxDataGet("magictool_toprocess_runs.sql");
    855855    if (!query) {
    856856        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     
    858858    }
    859859
     860    {
     861        psString limitString = psDBGenerateLimitSQL( 100 );
     862        psStringAppend(&query, " %s", limitString);
     863        psFree(limitString);
     864    }
    860865
    861866    if (!p_psDBRunQueryF(config->dbh, query, whereString ? whereString :  "")) {
     
    868873    psFree(query);
    869874
    870     psArray *magicTree = p_psDBFetchResult(config->dbh);
    871     if (!magicTree) {
     875    psArray *magicRuns = p_psDBFetchResult(config->dbh);
     876    if (!magicRuns) {
    872877        psErrorCode err = psErrorCodeLast();
    873878        switch (err) {
     
    882887        return false;
    883888    }
    884     if (!psArrayLength(magicTree)) {
     889    if (!psArrayLength(magicRuns)) {
    885890        psTrace("magictool", PS_LOG_INFO, "no rows found");
    886         psFree(magicTree);
     891        psFree(magicRuns);
    887892        return true;
    888893    }
    889894
    890     // entries are ordered by magic_id
    891     long index = 0;
    892     while (index <  psArrayLength(magicTree)) {
    893         bool status;
     895    query = pxDataGet("magictool_toprocess_tree.sql");
     896    if (!query) {
     897        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     898        return false;
     899    }
     900
     901    for (psS64 index = 0; index < psArrayLength(magicRuns); index++) {
    894902        if (limit && (psArrayLength(output) >= limit)) {
    895903            break;
    896904        }
    897         psS64 current_magic_id = psMetadataLookupS64(&status, magicTree->data[index], "magic_id");
     905        bool status;
     906        psS64 magic_id = psMetadataLookupS64(&status, magicRuns->data[index], "magic_id");
    898907        if (!status) {
    899908            psAbort("failed to lookup value for magic_id column");
    900909        }
    901 
    902         // find the end of this block
    903         long first = index;
    904         long last = index;
    905         for (long i = index + 1; i < psArrayLength(magicTree); i++) {
    906             psS64 magic_id = psMetadataLookupS64(&status, magicTree->data[i], "magic_id");
    907             if (!status) {
    908                 psAbort("failed to lookup value for magic_id column");
     910       
     911        whereString = NULL;
     912        psStringAppend(&whereString, "\nAND (magic_id = %" PRId64 ")", magic_id);
     913        if (!p_psDBRunQueryF(config->dbh, query, whereString )) {
     914            psError(PS_ERR_UNKNOWN, false, "database error");
     915            psFree(whereString);
     916            psFree(query);
     917            return false;
     918        }
     919        psFree(whereString);
     920        psArray *magicTree = p_psDBFetchResult(config->dbh);
     921        if (!magicTree) {
     922            psErrorCode err = psErrorCodeLast();
     923            switch (err) {
     924                case PS_ERR_DB_CLIENT:
     925                    psError(PXTOOLS_ERR_SYS, false, "database error");
     926                case PS_ERR_DB_SERVER:
     927                    psError(PXTOOLS_ERR_PROG, false, "database error");
     928                default:
     929                    psError(PXTOOLS_ERR_PROG, false, "unknown error");
    909930            }
    910             if (magic_id != current_magic_id) {
    911                 break;
    912             }
    913             last = i;
    914         }
    915 
    916         index = last + 1;
    917 
    918         psHash *forest = psHashAlloc(last - first + 1);
     931
     932            return false;
     933        }
     934        psS64 length = psArrayLength(magicTree);
     935        if (!length) {
     936            psTrace("magictool", PS_LOG_INFO, "no rows found for magic_id %" PRId64, magic_id);
     937            psFree(magicTree);
     938            continue;
     939        }
     940
     941        psHash *forest = psHashAlloc(length);
    919942
    920943        // convert the array of metadata into a pxTree structure
    921         for (long i = first; i <= last; i++) {
     944        for (long i = 0; i < length; i++) {
    922945            bool status;
    923946            psString node = psMetadataLookupStr(&status, magicTree->data[i], "node");
     
    944967        pxTreeCrawl(root, findReadyNodes, output);
    945968        psFree(root);
    946 
    947     }
    948     psFree(magicTree);
     969        psFree(magicTree);
     970    }
    949971
    950972    if (psArrayLength(output)) {
Note: See TracChangeset for help on using the changeset viewer.