tii

Tcl-based suite for working with ii/idec protocol
git clone git://git.luxferre.top/tii.git
Log | Files | Refs | README

commit dc2df5265f8be75e06ea38dc308b5bcdde9801a8
parent 7f8b07a9e54dd9aebda54fe158d7bc0dc74e8266
Author: Luxferre <lux@ferre>
Date:   Fri, 25 Oct 2024 16:12:04 +0300

Implemented adaptive fetching using IDEC extensions

Diffstat:
Mtiifetch.tcl | 52++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 40 insertions(+), 12 deletions(-)

diff --git a/tiifetch.tcl b/tiifetch.tcl @@ -154,7 +154,9 @@ proc getfile {url} { } https - http { 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 {}} } @@ -211,26 +213,52 @@ proc fetchiidb {url echos dbfile dolog maxids} { set echos [split $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 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 set curecho "" - set datalines [split $echodata "\n"] set echomap "" # build the map of lists of message IDs foreach line $datalines { set line [string trim $line] - # detect if the line is related to echo name or message ID - if {[string first "." $line] eq -1} { # message ID - if {[string length $line] == 20} { # filter out invalid IDs - if {$curecho ne ""} { - dict lappend echomap $curecho $line + if {$line ne ""} { + # detect if the line is related to echo name or message ID + if {[string first "." $line] eq -1} { # message ID + if {[string length $line] == 20} { # filter out invalid IDs + 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"}