~grubng-dev/grubng/tools-urlsdb

« back to all changes in this revision

Viewing changes to Database.cs

  • Committer: thindil
  • Date: 2011-04-21 10:23:53 UTC
  • Revision ID: thindil2@gmail.com-20110421102353-f6szsgmqmfo8hq5j
some code optimization

Show diffs side-by-side

added added

removed removed

Lines of Context:
247
247
                {
248
248
                        int amount = 0;
249
249
                        System.Collections.Generic.List<string> delcmds = new System.Collections.Generic.List<string>();
250
 
                        ParseURLs parseulrs = new ParseURLs();
251
 
                        foreach (string url in urls)
 
250
                        using (ParseURLs parseulrs = new ParseURLs())
252
251
                        {
253
 
                                delcmds.Add("DELETE FROM `urlslist` WHERE `url_hash`='" + parseulrs.GetHash(url) + "';");
 
252
                                foreach (string url in urls)
 
253
                                {
 
254
                                        delcmds.Add("DELETE FROM `urlslist` WHERE `url_hash`='" + parseulrs.GetHash(url) + "';");
 
255
                                }
254
256
                        }
255
 
                        parseulrs.Dispose();
256
257
                        using (IDbConnection dbcon = new MySqlConnection(this.connectionString))
257
258
                        {
258
259
                                dbcon.Open();
390
391
                                        {
391
392
                                                dbcmd.CommandText = "SELECT SQL_NO_CACHE `url` FROM `urlslist` WHERE `http_code1`=" + status + " AND `http_code2`=" + 
392
393
                                                        status + " AND `http_code3`=" + status + ";";
393
 
                                                IDataReader reader = dbcmd.ExecuteReader();
394
 
                                                StringBuilder solrcommand = new StringBuilder();
395
 
                                                solrcommand.Append("<delete>");
396
 
                                                string scommand = String.Empty;
397
 
                                                while (reader.Read())
 
394
                                                using (IDataReader reader = dbcmd.ExecuteReader())
398
395
                                                {
399
 
                                                        solrcommand.Append("<id>http://");
400
 
                                                        solrcommand.Append(System.Security.SecurityElement.Escape(reader.GetString(0)));
401
 
                                                        solrcommand.Append("</id>");
402
 
                                                        amount ++;
403
 
                                                        if (amount == 2000)
 
396
                                                        StringBuilder solrcommand = new StringBuilder();
 
397
                                                        solrcommand.Append("<delete>");
 
398
                                                        string scommand = String.Empty;
 
399
                                                        while (reader.Read())
404
400
                                                        {
405
 
                                                                solrcommand.Append("</delete>");
406
 
                                                                scommand = System.Text.RegularExpressions.Regex.Replace(solrcommand.ToString(), @"[\p{IsC}]", String.Empty);
407
 
                                                                MainClass.SendCommand(scommand, "Solr");
408
 
                                                                MainClass.SendCommand("<commit/>", "Solr");
409
 
                                                                solrcommand.Remove(0, solrcommand.Length);
410
 
                                                                solrcommand.Append("<delete>");
411
 
                                                                amount = 0;
 
401
                                                                solrcommand.Append("<id>http://");
 
402
                                                                solrcommand.Append(System.Security.SecurityElement.Escape(reader.GetString(0)));
 
403
                                                                solrcommand.Append("</id>");
 
404
                                                                amount ++;
 
405
                                                                if (amount == 2000)
 
406
                                                                {
 
407
                                                                        solrcommand.Append("</delete>");
 
408
                                                                        scommand = System.Text.RegularExpressions.Regex.Replace(solrcommand.ToString(), @"[\p{IsC}]", String.Empty);
 
409
                                                                        MainClass.SendCommand(scommand, "Solr");
 
410
                                                                        MainClass.SendCommand("<commit/>", "Solr");
 
411
                                                                        solrcommand.Remove(0, solrcommand.Length);
 
412
                                                                        solrcommand.Append("<delete>");
 
413
                                                                        amount = 0;
 
414
                                                                }
412
415
                                                        }
 
416
                                                        solrcommand.Append("</delete>");
 
417
                                                        scommand = System.Text.RegularExpressions.Regex.Replace(solrcommand.ToString(), @"[\p{IsC}]", String.Empty);
 
418
                                                        MainClass.SendCommand(scommand, "Solr");
 
419
                                                        MainClass.SendCommand("<commit/>", "Solr");
 
420
                                                        reader.Close();
413
421
                                                }
414
 
                                                reader.Close();
415
 
                                                reader.Dispose();
416
 
                                                solrcommand.Append("</delete>");
417
 
                                                scommand = System.Text.RegularExpressions.Regex.Replace(solrcommand.ToString(), @"[\p{IsC}]", String.Empty);
418
 
                                                MainClass.SendCommand(scommand, "Solr");
419
 
                                                MainClass.SendCommand("<commit/>", "Solr");
420
422
                                        }
421
423
                                        dbcmd.CommandText = "DELETE FROM `urlslist` WHERE `http_code1`=" + status + " AND `http_code2`=" + status + 
422
424
                                                " AND `http_code3`=" + status + ";";