ditched x/c functionality in favor of binary expansion

This commit is contained in:
Luxferre
2024-10-25 18:42:28 +03:00
parent 2961f769b1
commit 639de755f6
2 changed files with 33 additions and 22 deletions
+3 -6
View File
@@ -40,12 +40,9 @@ In case of multi-line responses, the newline separator must be "\n" character
Request: GET /list.txt
Response: newline-separated list of echo_name:msg_count:echo_description
- Fetching the echo message count (IDEC extension) -
Request: GET /x/c/echo.1.name/echo.2.name/..
Response: newline separated list of echo_name:msg_count
Note: msg_count must not decrease even if some messages are deleted.
Some nodes (e.g. ii-php) still can violate this rule, so the message count
reported by nodes still should not be the basis for any client-side logic.
- Listing messages in the echo (s) -
@@ -87,7 +84,7 @@ The maximum length of the tmsg field must be 87382 bytes.
Request: GET /x/features
Response: newline-separated list of supported non-standard URL paths
(x/c, u/e, /list.txt etc)
(u/e, /list.txt etc)
Note: if the /x/features path is unavailable, the client must assume that no
IDEC extensions except /list.txt are supported by the server.
+30 -16
View File
@@ -212,31 +212,45 @@ proc fetchiidb {url echos dbfile dolog maxids} {
} else {
set echos [split $echos "/,;"]
}
if {$dolog eq 1} {puts "Echos to fetch: $echos"}
set echos [lmap s $echos {string trim $s}]
if {$dolog eq 1} {puts "Echos to fetch: $echos"}
if {$dolog eq 1} {puts "Building message indexes..."}
# 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
if {[lsearch $featurelist u/e] > -1} {
# echoname => localcount map
set localcounts [msgdb eval {SELECT `echoname`, COUNT(`id`) FROM `msg` GROUP BY `echoname`;}]
foreach ename $echos {
if {$ename ne ""} {
set localdata ""
set localcount 0
if {[dict exists $localcounts $ename]} {
set localcount [dict get $localcounts $ename]
}
if {$localcount > 12} {
set diff 6
set needsync 1
while {$needsync eq 1} {
incr diff $diff
set localdata [getfile [string cat $url "/u/e/" $ename "/-$diff:1"]]
# control message id
set cmsg [string trim [lindex [split $localdata \n] 1]]
msgdb eval {SELECT `msgid` FROM `msg` WHERE `msgid` = $cmsg;} row {
if {[string trim $row(msgid)] eq $cmsg} {
set needsync 0
}
}
}
set localdata [getfile [string cat $url "/u/e/" $ename "/-$diff:$diff"]]
} else {
set localdata [getfile [string cat $url "/u/e/" $ename]]
}
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]