Changeset 1336

Show
Ignore:
Timestamp:
02/16/07 22:37:19 (2 years ago)
Author:
jm3
Message:

massive query cleanup and debugging

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • feedmelinks/action.php

    r1334 r1336  
    169169                                                $valuesClause = "$valuesClause($link, $tag) "; 
    170170                                                $c++; 
    171                                                 $qs = "INSERT INTO links_tags_xref VALUES($link, $tag);"
     171                                                $qs = getQuery( "add_new_category_xref", $link, $tag )
    172172                                                $q = mysql_query( $qs ); 
    173173                                                if( ! $q ) { 
  • feedmelinks/edit-folder.php

    r1334 r1336  
    167167                        } 
    168168                         
    169                         $folderId = addFolder( urlencode( $name ), $u ); 
     169                        $folderId = addFolder( $name, $u ); 
    170170                        if( $debug ) 
    171171                                echo "\$folderId: $folderId<br/>"; 
  • feedmelinks/import/present-clean-pre-flight-input.inc.php

    r1177 r1336  
    1919                new tags to be created: 
    2020        </div> 
    21         <form name="tags"
     21        <div
    2222<% 
    2323        for( $i = 0; $i < $ts; $i++ ) { 
    2424                $line = rtrim( $tags[$i] ); 
     25                if( ! $line ) 
     26                        continue; 
    2527                if( substr( $line, 0, 2 ) == "X " ) { 
    2628                        $tag = preg_replace( "/^X /", "", $line ); 
    27                         echo row_wrap( " <span class='subtle'>Ignoring duplicate tag $tag</span>", ($i % 2 == 0) ? 1 : 0 )
     29                        echo row_wrap( " <span class='subtle'>Ignoring duplicate tag $tag</span>", ($i % 2 == 0) ? 1 : 0 ) . "\n"
    2830                } else { 
    2931                        ++$num_tags; 
    30                         echo row_wrap( " <span class='hot'><label><!-- input type='checkbox' checked='checked' name='tag' value='$line' /-->Create tag: </label> $line</span>", ($i % 2 == 0) ? 1 : 0 )
     32                        echo row_wrap( " <span class='hot'>Create tag: $line</span>", ($i % 2 == 0) ? 1 : 0 ) . "\n"
    3133                } 
    3234                echo "</div>\n"; 
    3335        } 
    3436%> 
    35 </form
     37       </div
    3638</div> 
    3739 
     
    4749                $name = $l[1]; 
    4850                $max_length = 65; 
     51                if( ! $line )  
     52                        continue; 
    4953                if( substr( $line, 0, 2 ) == "X " ) { 
    5054                        $url = getCompactString( preg_replace( "/^X /", "", $url ), $max_length); 
     
    5862        } 
    5963%> 
     64        </div> 
    6065</div> 
    61 <% 
    62         $html = ob_get_clean(); 
    63 %> 
     66 
     67<?php $html = ob_get_clean(); ?> 
    6468 
    6569<center> 
     
    7175 
    7276<% 
    73         shout( "Ready to Import?", "Our link-importing robot found <b>$num_links new links</b> and <b>$num_tags new tags</b> to create. If the links below look correct, <b>scroll to the bottom of the list and click <u>Import</u></b>. <p/>Because you are importing a batch of potentially personal favorites, these links <b>will&nbsp;not</b> be publicly viewable on Feed Me Links until you mark them public. (Remember, nothing will be added until you scroll down and click <b>Import</b>)" ); 
     77        shout( "Ready to Import?", "Our link-importing robot found <b>$num_links new link" . ($num_links == 1 ? "" : "s") . "</b> and <b>$num_tags new tag" . ($num_tags == 1 ? "" : "s") . "</b> to create. If the links below look correct, <b>scroll to the bottom of the list and click <u>Import</u></b>. <p/>Because you are importing a batch of potentially personal favorites, these links <b>will&nbsp;not</b> be publicly viewable on Feed Me Links until you mark them public. (Remember, nothing will be added until you scroll down and click <b>Import</b>)" ); 
    7478 
    7579        echo $html; 
  • feedmelinks/import/processing.php

    r1334 r1336  
    1313 
    1414                # 6. using the prep files, generate the proper SQL commands to 
    15                 # INSERT link, tag, and link/tag rows. need to do some heavy state 
     15                # insert link, tag, and link/tag rows. need to do some heavy state 
    1616                # caching. 
    1717                 
     
    4242                                #e( "$i ::" ); 
    4343                                $l = preg_split( "/$delimeter/", $line ); 
    44                                 $url = urlencode( $l[0] ); 
    45                                 $name = urlencode( $l[1] ); 
    4644                                $taglist = array_slice( $l, 2, sizeof( $l )); 
    47                                 $qs = "INSERT INTO links VALUES( NULL, '$url', '$name', NULL, NULL, '$user', NULL, 1 );\n"; 
    48                                 $q = mysql_query( $qs ); 
    49                                 if( !$q ) { 
     45                                $inserted_id = addLinkSimple( $l[0], $l[1], $user, 1 ); 
     46                                if( !$inserted_id ) 
    5047                                        ++$db_errors; 
    51                                         l( "INSERTING LINK FAILED: $qs\n" ); 
    52                                 } 
    5348 
    5449                                # B. the tag / link associations 
     
    7974                                                } 
    8075 
    81                                                 # FINALLY, WITH NO RECOURSE LEFT TO US, WE INSERT THE NEW TAG IN THE DB 
     76                                                # Finally, with no recourse left to us, we insert the new tag in the db 
    8277                                                if( $run_query ) { 
    83                                                         $qs = "INSERT INTO tags VALUES( NULL, '$user', '$tag', '' );\n"
     78                                                        $qs = getQuery( "add_tag", $user, $tag )
    8479                                                        $q = mysql_query( $qs ); 
    8580                                                        if( !$q ) { 
    8681                                                                ++$db_errors; 
    87                                                                 l( "INSERTING TAG FAILED: $qs\n" ); 
     82                                                                log_mesg_to( "Inserting tag $tag for $u failed: $qs", "global" ); 
    8883                                                        } else { 
    8984 
    90                                                                 # FIRST, WE SAVE THE NEW TAG ID FOR INSERTING IN THE XREF TABLE 
     85                                                                # first, we save the new tag id for inserting in the xref table 
    9186                                                                $current_tag_ID = mysql_insert_id(); 
    9287 
     
    105100                                         
    106101                                        if( $current_link_ID && $current_tag_ID ) { 
    107                                                 $qs = "INSERT INTO links_tags_xref VALUES( $current_link_ID, $current_tag_ID );\n"
     102                                                $qs = getQuery( "add_new_category_xref", $current_link_ID, $current_tag_ID )
    108103                                                $q = mysql_query( $qs ); 
    109104                                                if( !$q ) { 
    110105                                                        ++$db_errors; 
    111                                                         l( "INSERTING LINK-TAG XREF FAILED: $qs\n" ); 
     106                                                        l( "Inserting link-tag xref failed: $qs\n" ); 
    112107                                                } 
    113108                                        } else { 
    114109                                                ++$db_errors; 
    115                                                 l( "current_link_ID and/or current_tag_ID were 0, meaning a database INSERT failed on import" ); 
     110                                                l( "current_link_ID and/or current_tag_ID were 0, meaning a database Insert failed on import" ); 
    116111                                        } 
    117112                                } 
  • feedmelinks/modules/main-controller.inc.php

    r1331 r1336  
    4141 
    4242                                # then we add the link: 
    43                                 $q = addLink( $url, $name, $userid, $folderId, $isPrivate, $options ); 
     43                                $q = addLinkSimple( $url, $name, $userid, $isPrivate ); 
    4444                                if( $q ) { 
    4545                                        echo "link added!<br />\n";  
     
    8686--> 
    8787<?php 
    88                         $q = addLink( $url, $name, $userid, $groupid, $isPrivate, $options ); 
     88                        $q = addLinkSimple( $url, $name, $userid, $isPrivate ); 
    8989                        if( $q ) { 
    9090                                echo "link added!<br />\n";  
  • feedmelinks/modules/utils.inc.php

    r1334 r1336  
    20692069    INSERT INTO links_tags_xref VALUES( " . $args[1] . ", " . $args[2] . " ) "; 
    20702070   
     2071  } else if( $argWhichQuery  == "add_link" ) { 
     2072    return " 
     2073                INSERT INTO links VALUES(NULL,'" . urlencode( $args[1] ) . "','" . urlencode(escapeQuotes($args[2])) . "', NULL, NULL,'" . urlencode( $args[3] ) . "', NULL, " . $args[4] . ");"; 
     2074 
     2075  } else if( $argWhichQuery  == "add_tag" ) { 
     2076                $isPrivate = $args[3] ? 1 : 0; 
     2077                return " 
     2078                INSERT INTO tags VALUES(NULL,'" . urlencode( $args[1] ) . "','" . urlencode( $args[2] ) . "','', $isPrivate);";  
     2079   
    20712080  } else if( $argWhichQuery  == "tag_by_name" ) { 
    20722081    return " 
     
    21972206    mysql_selectdb( getDBName() ); 
    21982207    foreach( $argCats as $catNum ) { 
    2199       $qs =  "INSERT INTO links_tags_xref VALUES( $argId, $catNum );"
     2208                       $qs = getQuery( "add_new_category_xref", $argId, $catNum )
    22002209      $q = mysql_query( $qs ); 
    22012210      if( ! $q ) { 
     
    28872896 
    28882897function addFolderDriver( $argFolderName, $argUserId, $argIsPrivate ) { 
    2889 $debug=1; 
    28902898  if( $argFolderName &&  $argUserId ) { 
    28912899 
     
    29082916      if( $debug ) 
    29092917        echo "DEBUG: \"$argFolderName\" is a new tag -- let's add it:<br/>"; 
    2910       $qs = "INSERT INTO tags VALUES(NULL,'$argUserId','$argFolderName','', $argIsPrivate);";  
     2918      $qs = getQuery( "add_tag", $argUserId, $argFolderName, $argIsPrivate); 
    29112919      if( $debug ) 
    29122920        echo "DEBUG: $qs<br/>"; 
     
    29923000        } 
    29933001 
    2994   $qs = "INSERT INTO links VALUES(NULL,'" . urlencode( $argUrl ) . "','" . urlencode(escapeQuotes($argName)) . "', NULL, NULL,'" . urlencode( $argSubmitter ) . "', NULL, $isPrivate );"
     3002       $qs = getQuery( "add_link", $argUrl, $argName, $argSubmitter, $isPrivate )
    29953003  if( $debug )  
    29963004    echo "qs: $qs<br>"; 
     
    30013009} 
    30023010 
     3011# deprecated; call addLinkSimple() instead 
    30033012function addLink( $argUrl, $argName, $argSubmitter, $argFolderId, $argPrivate, $argOptions ) { 
    30043013  if(  !( $argUrl &&  $argName && $argSubmitter )) 
     
    30083017    return 0; # FIXME: signal this error back to the user!!!! 
    30093018   
    3010   if( ! $argFolderId || $argFolderId == "NULL" ) { 
    3011     $q = addLinkSimple( urldecode( $argUrl ), urldecode( $argName ), urldecode( $argSubmitter ) ); 
    3012   } else { 
    3013     $isPrivate = $argPrivate ? $argPrivate : "NULL"; 
    3014  
    3015     # spammers and newbies' links are private 
    3016     if( get_tag_to_link_ratio( $argSubmitter ) > get_max_ttl_ratio() ) { 
    3017       $isPrivate = 1; 
    3018                         log_mesg_to( get_ip() . ": privatizing new link from $argSubmitter due to T:L ratio", "security" ); 
    3019                 } 
    3020  
    3021     mysql_connect(); 
    3022     mysql_selectdb( getDBName() ); 
    3023  
    3024     # check to make sure the folder is not private; if it is, make the link private too: 
    3025     $folderName = getNameForFolder( $argFolderId ); 
    3026     if( $folderName && (! isPublicFolder( $argFolderId ))) 
    3027       $isPrivate = 1; 
    3028  
    3029     $qs = "INSERT INTO links VALUES(NULL,'$argUrl','$argName', NULL, NULL,'$argSubmitter', $argFolderId, '$argOptions', $isPrivate );"; 
    3030     $q = mysql_query( $qs ); 
    3031     conClose(); 
    3032   } 
     3019        $q = addLinkSimple( urldecode( $argUrl ), urldecode( $argName ), urldecode( $argSubmitter ) ); 
    30333020  return $q; 
    30343021} 
  • feedmelinks/recent-kompact.php

    r1178 r1336  
    33        $page = "recent-kompact"; 
    44        include_once( "modules/utils.inc.php" ); 
    5         $tok =  $authenticated = $_COOKIE["c_pass_token"]; 
    6         $u   =  $sessionUserId = $_COOKIE["c_uid"]; 
    7  
    85        $site = getSiteUrl(); 
    96 
     
    1815<% 
    1916                $con_recentKompact = mysql_connect(); 
    20                 mysql_selectdb( getDBName() ); 
    2117 
    2218                $qs2 = getQuery( "num_links" );