Implemented adaptive fetching using IDEC extensions
This commit is contained in:
+40
-12
@@ -154,7 +154,9 @@ proc getfile {url} {
|
|||||||
}
|
}
|
||||||
https - http {
|
https - http {
|
||||||
set hs [::http::geturl $url -binary 1 -keepalive 1 -timeout 5000]
|
set hs [::http::geturl $url -binary 1 -keepalive 1 -timeout 5000]
|
||||||
return [::http::data $hs]
|
if {[::http::ncode $hs] eq "200"} {
|
||||||
|
return [::http::data $hs]
|
||||||
|
} else {return {}}
|
||||||
}
|
}
|
||||||
default {return {}}
|
default {return {}}
|
||||||
}
|
}
|
||||||
@@ -211,26 +213,52 @@ proc fetchiidb {url echos dbfile dolog maxids} {
|
|||||||
set echos [split $echos "/,;"]
|
set echos [split $echos "/,;"]
|
||||||
}
|
}
|
||||||
if {$dolog eq 1} {puts "Echos to fetch: $echos"}
|
if {$dolog eq 1} {puts "Echos to fetch: $echos"}
|
||||||
# pass the echo list and fetch the message IDs
|
|
||||||
set echos [lmap s $echos {string trim $s}]
|
set echos [lmap s $echos {string trim $s}]
|
||||||
set echodata [getfile [string cat $url "/u/e/" [join $echos "/"]]]
|
# get the IDEC extended feature list
|
||||||
|
set featurelist ""
|
||||||
|
catch {set featurelist [getfile [string cat $url "/x/features"]]}
|
||||||
|
set featurelist [lmap s [split $featurelist \n] {string trim $s}]
|
||||||
|
set datalines ""
|
||||||
|
if {([lsearch $featurelist x/c] > -1 ) && ([lsearch $featurelist u/e] > -1)} {
|
||||||
|
# get message count in every echo of our choice
|
||||||
|
set countdata [getfile [string cat $url "/x/c/" [join $echos "/"]]]
|
||||||
|
foreach cd $countdata {
|
||||||
|
set cdparts [split $cd :]
|
||||||
|
if {[llength $cdparts] > 1} {
|
||||||
|
set ename [lindex $cdparts 0]
|
||||||
|
set rcount [lindex $cdparts 1]
|
||||||
|
set lcount [msgdb eval {SELECT COUNT (DISTINCT `id`) FROM `msg` WHERE `echoname` = $ename;}]
|
||||||
|
# get the difference between remote and local counts
|
||||||
|
set diff [expr {$rcount - $lcount}]
|
||||||
|
if {$diff > 0} { # we have something to fetch
|
||||||
|
set localdata [getfile [string cat $url "/u/e/" $ename "/-$diff:$diff"]]
|
||||||
|
append datalines [string trim $localdata] \n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else { # no extended feature support, pass the echo list and fetch the message IDs
|
||||||
|
set echodata [getfile [string cat $url "/u/e/" [join $echos "/"]]]
|
||||||
|
set datalines [split $echodata \n]
|
||||||
|
}
|
||||||
# iterate over the fetched data and fetch corresponding messages
|
# iterate over the fetched data and fetch corresponding messages
|
||||||
set curecho ""
|
set curecho ""
|
||||||
set datalines [split $echodata "\n"]
|
|
||||||
set echomap ""
|
set echomap ""
|
||||||
# build the map of lists of message IDs
|
# build the map of lists of message IDs
|
||||||
foreach line $datalines {
|
foreach line $datalines {
|
||||||
set line [string trim $line]
|
set line [string trim $line]
|
||||||
# detect if the line is related to echo name or message ID
|
if {$line ne ""} {
|
||||||
if {[string first "." $line] eq -1} { # message ID
|
# detect if the line is related to echo name or message ID
|
||||||
if {[string length $line] == 20} { # filter out invalid IDs
|
if {[string first "." $line] eq -1} { # message ID
|
||||||
if {$curecho ne ""} {
|
if {[string length $line] == 20} { # filter out invalid IDs
|
||||||
dict lappend echomap $curecho $line
|
if {$curecho ne ""} {
|
||||||
|
dict lappend echomap $curecho $line
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else { # echo name
|
||||||
|
set curecho $line
|
||||||
|
dict set echomap $curecho ""
|
||||||
}
|
}
|
||||||
} else { # echo name
|
|
||||||
set curecho $line
|
|
||||||
dict set echomap $curecho ""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if {$dolog eq 1} {puts "Echomap built"}
|
if {$dolog eq 1} {puts "Echomap built"}
|
||||||
|
|||||||
Reference in New Issue
Block a user