OSDN Git Service

文字列比較や文字列コピーを減らしてさらに高速化、一般的なスクリプトで元々の約2.3倍
[winbottle/winbottle.git] / bottleclient / Logs.pas
index 065e034..037c538 100755 (executable)
@@ -59,7 +59,7 @@ type
 
   EXMLFileOpenException = class(Exception);
 
-  TBottleLogDownLoadCondition = packed record
+  TBottleLogDownloadCondition = packed record
     IsRange: boolean;
     RecentCount: integer;
     DateLo: TDateTime;
@@ -112,6 +112,7 @@ type
     FOldSortColumn: TBottleLogSortType; // \83\8d\83O\91\8b
     FOldSortDesc: boolean;   // \83\8d\83O\91\8b
     FSelectedIndex: integer;
+    FLastDownloadCondition: TBottleLogDownloadCondition;
     FOnLoadWork: TNotifyEvent; // \83\8d\83O\91\8b
     FImagePath: String; // HTML\8fo\97Í\8e\9e\82ÌIMG\83^\83O\82Ì\83p\83X(\91\8a\91Î\82Ü\82½\82Í\90â\91Î\83p\83X)
     FImageFiles: TStringList;
@@ -157,6 +158,8 @@ type
     procedure LoadFromXMLFile(const FileName: String);
     procedure SaveToHTML(const FileName: String;
       const Options: THTMLOutputOptions; SsParser: TSsParser);
+    procedure ExtractUniqueChannels(Target: TStrings);
+    procedure ExtractUniqueGhosts(Target: TStrings);
     property OnHTMLOutputWork: TBottleLogHTMLOutputWork read FOnHTMLOutputWork write SetOnHTMLOutputWork;
   end;
 
@@ -369,6 +372,28 @@ begin
   if Assigned(FOnLoadFailure) then FOnLoadFailure(self, ErrorMessage);
 end;
 
+procedure TBottleLogList.ExtractUniqueChannels(Target: TStrings);
+var i: integer;
+begin
+  // \82±\82Ì\83\8d\83O\92\86\82Ì\83`\83\83\83\93\83l\83\8b\82ð\8eæ\82è\8fo\82·
+  // TStrings\82Ì\8eÀ\91\95\82ÍTHashedStringList\90\84\8f§
+  for i := 0 to Count-1 do
+    if Target.IndexOf(Bottles[i].Channel) < 0 then
+      if Bottles[i].Channel <> '' then
+        Target.Add(Bottles[i].Channel);
+end;
+
+procedure TBottleLogList.ExtractUniqueGhosts(Target: TStrings);
+var i: integer;
+begin
+  // \82±\82Ì\83\8d\83O\92\86\82Ì\83S\81[\83X\83g\82ð\8eæ\82è\8fo\82·
+  // TStrings\82Ì\8eÀ\91\95\82ÍTHashedStringList\90\84\8f§
+  for i := 0 to Count-1 do
+    if Target.IndexOf(Bottles[i].Ghost) < 0 then
+      if Bottles[i].Ghost <> '' then
+        Target.Add(Bottles[i].Ghost);
+end;
+
 function TBottleLogList.GetBottles(Index: integer): TLogItem;
 begin
   Result := Items[Index] as TLogItem;
@@ -423,6 +448,8 @@ end;
 
 procedure TBottleLogList.LoadFromStream(Stream: TStream);
 var i: integer;
+    agree: integer;
+    vote: integer;
     SourceStream: TStringStream;
     Source: TStringList;
     LogItem: TLogItem;
@@ -451,13 +478,24 @@ begin
       end;
       Self.Clear;
       while (i + 7) < Source.Count do begin
-        LogItem := TLogItem.Create(ltBottle, Source[i+1], Source[i+2],
-          Source[i+7], Source[i+3], S2D(Source[i]));
-        LogItem.Votes  := StrToInt(Source[i+5]);
-        LogItem.Agrees := StrToInt(Source[i+6]);
-        LogItem.State := lsOpened;
+        vote := StrToInt(Source[i+5]);
+        agree := StrToInt(Source[i+6]);
+
+        //\93\8a\95[\81E\93¯\88Ó\8fð\8c\8f\8ew\92è\82Í\82±\82±\82Å\8eÀ\8c»
+        //FIXME FIXME - \97Í\8bZ\82·\82¬\82Ü\82·\81A\81A\81A
+        if vote >= FLastDownloadCondition.MinVote then begin
+          if agree >= FLastDownloadCondition.MinAgree then begin
+            LogItem := TLogItem.Create(ltBottle, Source[i+1], Source[i+2],
+              Source[i+7], Source[i+3], S2D(Source[i]));
+
+            LogItem.Votes  := vote;
+            LogItem.Agrees := agree;
+            LogItem.State  := lsOpened;
+            Self.Add(LogItem);
+          end;
+        end;
+
         i := i + 8;
-        Self.Add(LogItem);
       end;
     finally
       SourceStream.Free;
@@ -479,6 +517,8 @@ var Param: String;
 begin
   Self.Clear;
   AddSystemLog('\83_\83E\83\93\83\8d\81[\83h\92\86\82Å\82· - \83T\81[\83o\82©\82ç\89\9e\93\9a\91Ò\82¿');
+
+  FLastDownloadCondition := Cond;
   with Cond do begin
     if Cond.IsRange then begin
       Param := Format('year_lo=%d&month_lo=%d&day_lo=%d&year_hi=%d&month_hi=%d&day_hi=%d&',
@@ -487,13 +527,17 @@ begin
     end else begin
       Param := Format('recent=%d&', [RecentCount]);
     end;
-    Param := Param + Format('minvote=%d&minagree=%d&channel=%s&sort=timedesc&delimiter=%%0D%%0A',
-      [MinVote, MinAgree, ParamsEncode(Channel)]);
+    Param := Param + Format('channel=%s&sort=timedesc&delimiter=%%0D%%0A',
+      [ParamsEncode(Channel)]);
   end;
   FHttpThread := THTTPDownloadThread.Create(Pref.BottleServer, Pref.CgiFetchLog, Param);
   if Pref.UseHttpProxy then begin
     FHttpThread.ProxyServer := Pref.ProxyAddress;
     FHttpThread.ProxyPort   := Pref.ProxyPort;
+    if Pref.ProxyNeedAuthentication then begin
+      FHttpThread.ProxyUser := Pref.ProxyUser;
+      FHttpThread.ProxyPass := Pref.ProxyPass;
+    end;
   end;
   FHttpThread.FreeOnTerminate := true;
   FHttpThread.OnSuccess := HttpSuccess;