@@ -563,18 +563,25 @@ def stats_pro(day):
563563 f"select hour, data from access_ip where hour >= ?" ,
564564 t ,
565565 ):
566- hour = (
567- (q [0 ] + get_utc_offset ())
568- if not format_day
569- else (q [0 ] + get_utc_offset ()) // 24
570- )
571- data = DataInputStream (zstd .decompress (q [1 ]))
572- for ip , c in {
573- data .readString (): data .readVarInt () for _ in range (data .readVarInt ())
574- }.items ():
575- if hour not in s_ip :
576- s_ip [hour ] = defaultdict (int )
577- s_ip [hour ][ip ] += c
566+ hour = (q [0 ] + get_utc_offset ()) if not format_day else (q [0 ] + get_utc_offset ()) // 24
567+ try :
568+ data = DataInputStream (zstd .decompress (q [1 ]))
569+ for ip , c in {data .readString (): data .readVarInt () for _ in range (data .readVarInt ())}.items ():
570+ if hour not in s_ip :
571+ s_ip [hour ] = defaultdict (int )
572+ s_ip [hour ][ip ] += c
573+ except :
574+ new_data = DataOutputStream ()
575+ data_ip = {data .readString (old_data_read_varint (data )): old_data_read_varint (data ) for _ in range (old_data_read_varint (data ))}
576+ new_data .writeVarInt (len (data_ip ))
577+ for ip , c in data_ip .items ():
578+ new_data .writeString (ip )
579+ new_data .writeVarInt (c )
580+ if hour not in s_ip :
581+ s_ip [hour ] = defaultdict (int )
582+ s_ip [hour ][ip ] += c
583+ execute ("update access_ip set data = ? where hour = ?" , zstd .compress (new_data .io .getbuffer ()), hour )
584+
578585 addresses : defaultdict [location .IPInfo , int ] = defaultdict (int )
579586 for ips in s_ip .values ():
580587 for address , count in ips .items ():
@@ -596,3 +603,16 @@ def stats_pro(day):
596603 "bytes" : file_bytes ,
597604 "downloads" : file_download ,
598605 }
606+
607+
608+ def old_data_read_varint (input : DataInputStream ):
609+ i : int = 0
610+ j : int = 0
611+ k : int
612+ while 1 :
613+ k = int .from_bytes (input .read (1 ), byteorder = "big" )
614+ i |= (k & 0x7F ) << j * 7
615+ j += 1
616+ if (k & 0x80 ) != 128 :
617+ break
618+ return i
0 commit comments