torrust-tracker
torrust-tracker copied to clipboard
Refactor: rename `peer.updated` field in torrent detail endpoint
pub struct TorrentPeer {
pub peer_id: PeerId,
pub peer_addr: SocketAddr,
#[serde(serialize_with = "ser_instant")]
pub updated: std::time::Instant,
#[serde(with = "NumberOfBytesDef")]
pub uploaded: NumberOfBytes,
#[serde(with = "NumberOfBytesDef")]
pub downloaded: NumberOfBytes,
#[serde(with = "NumberOfBytesDef")]
pub left: NumberOfBytes,
#[serde(with = "AnnounceEventDef")]
pub event: AnnounceEvent,
}
@WarmBeer , would not it be nice to rename the updated field like this:
#[serde(serialize_with = "ser_instant")]
#[serde(rename(deserialize = "updated_milliseconds_ago", serialize = "updated_milliseconds_ago"))]
pub updated: std::time::Instant,
To get a json like this:
{
"info_hash": "4beb7001cb833968582c67f55cc59dcc6c8d3fe5",
"seeders": 1,
"completed": 0,
"leechers": 0,
"peers": [
{
"peer_id": {
"id": "2d7142343431302d7358376d33786d2877674179",
"client": "qBittorrent"
},
"peer_addr": "192.168.1.88:17548",
"updated_milliseconds_ago": 385,
"uploaded": 0,
"downloaded": 0,
"left": 0,
"event": "None"
}
]
}
I generally like to add the units in the attribute name.
We can use any other name like: not_updated_duration_in_msecs, not_updated_duration_in_msecs, ...
Originally posted by @josecelano in https://github.com/torrust/torrust-tracker/issues/60#issuecomment-1210719772
It seems the backend does not use it:
https://github.com/torrust/torrust-index-backend/blob/8fbbb5ba3a80d1206e56a82391cc49740e803f54/src/tracker.rs#L22
so it would be safe to rename it, at least for other projects in the organization. It's a breaking change for external projects using only this tracker.