Skip to content

Commit fd55879

Browse files
cmyuiclaude
andauthored
Remove fallback sessions (#47)
* Remove Amplitude integration Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Remove dead FallbackSession code FallbackSession was used for reading old bancho.py sessions from Redis but was never called anywhere in the codebase. Remove the struct, all helper functions, and clean up unused imports. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d8db096 commit fd55879

File tree

2 files changed

+2
-164
lines changed

2 files changed

+2
-164
lines changed

src/entities/sessions.rs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -28,58 +28,3 @@ pub struct CreateSessionArgs {
2828
pub silence_end: Option<chrono::DateTime<chrono::Utc>>,
2929
pub ip_address: IpAddr,
3030
}
31-
32-
#[derive(Debug, Deserialize, Serialize)]
33-
pub struct FallbackSession {
34-
pub token_id: String,
35-
pub user_id: i64,
36-
pub username: String,
37-
pub privileges: i64,
38-
pub whitelist: u8,
39-
pub kicked: bool,
40-
pub login_time: f64,
41-
pub ping_time: f64,
42-
pub utc_offset: i8,
43-
pub tournament: bool,
44-
pub block_non_friends_dm: bool,
45-
pub spectating_token_id: Option<String>,
46-
pub spectating_user_id: Option<String>,
47-
pub latitude: f64,
48-
pub longitude: f64,
49-
pub ip: String,
50-
pub country: u8,
51-
pub away_message: Option<String>,
52-
pub match_id: Option<i64>,
53-
54-
pub match_slot_id: Option<u8>,
55-
56-
pub last_np: Option<FallbackLastNp>,
57-
pub silence_end_time: i64,
58-
pub protocol_version: i64,
59-
pub spam_rate: i64,
60-
61-
// stats
62-
pub action_id: u8,
63-
pub action_text: String,
64-
pub action_md5: String,
65-
pub action_mods: i64,
66-
pub game_mode: u8,
67-
pub relax: bool,
68-
pub autopilot: bool,
69-
pub beatmap_id: i64,
70-
pub ranked_score: i64,
71-
pub accuracy: f32,
72-
pub playcount: i64,
73-
pub total_score: i64,
74-
pub global_rank: i64,
75-
pub pp: i64,
76-
77-
pub amplitude_device_id: Option<String>,
78-
}
79-
80-
#[derive(Debug, Deserialize, Serialize)]
81-
pub struct FallbackLastNp {
82-
pub beatmap_id: i64,
83-
pub mods: i64,
84-
pub accuracy: f32,
85-
}

src/repositories/sessions.rs

Lines changed: 2 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use crate::common::chat;
21
use crate::common::chat::safe_username;
3-
use crate::common::context::{Context, PoolContext};
2+
use crate::common::context::Context;
43
use crate::common::redis_json::Json;
5-
use crate::entities::sessions::{CreateSessionArgs, FallbackSession, Session};
4+
use crate::entities::sessions::{CreateSessionArgs, Session};
65
use redis::AsyncCommands;
76
use std::ops::DerefMut;
87
use uuid::Uuid;
@@ -161,109 +160,3 @@ pub async fn set_private_dms<C: Context>(
161160
session.private_dms = private_dms;
162161
update(ctx, session).await
163162
}
164-
165-
const FALLBACK_SESSIONS_KEY: &str = "bancho:tokens:json";
166-
167-
fn make_fallback_user_id_key(user_id: i64) -> String {
168-
format!("bancho:tokens:ids:{user_id}")
169-
}
170-
171-
fn make_fallback_username_key(username: &str) -> String {
172-
let safe_username = chat::safe_username(username);
173-
format!("bancho:tokens:names:{safe_username}")
174-
}
175-
176-
fn make_fallback_key(session_id: &str) -> String {
177-
format!("bancho:tokens:{session_id}")
178-
}
179-
180-
fn make_fallback_channels_key(session_id: &str) -> String {
181-
format!("{}:channels", make_fallback_key(session_id))
182-
}
183-
184-
fn make_fallback_spectators_key(session_id: &str) -> String {
185-
format!("{}:spectators", make_fallback_key(session_id))
186-
}
187-
188-
fn make_fallback_streams_key(session_id: &str) -> String {
189-
format!("{}:streams", make_fallback_key(session_id))
190-
}
191-
192-
fn make_fallback_stream_offsets_key(session_id: &str) -> String {
193-
format!("{}:stream_offsets", make_fallback_key(session_id))
194-
}
195-
196-
fn make_fallback_message_history_key(session_id: &str) -> String {
197-
format!("{}:message_history", make_fallback_key(session_id))
198-
}
199-
200-
fn make_fallback_sent_away_messages_key(session_id: &str) -> String {
201-
format!("{}:sent_away_messages", make_fallback_key(session_id))
202-
}
203-
204-
fn make_fallback_processing_lock_key(session_id: &str) -> String {
205-
format!("{}:processing_lock", make_fallback_key(session_id))
206-
}
207-
208-
fn make_fallback_user_stream_key(session_id: &str) -> String {
209-
format!("bancho:streams:tokens/{session_id}:messages")
210-
}
211-
212-
fn make_fallback_user_stream_messages_key(session_id: &str) -> String {
213-
format!("bancho:streams:tokens/{session_id}:messages:messages")
214-
}
215-
216-
pub async fn fetch_one_fallback<C: Context>(
217-
ctx: &C,
218-
session_id: Uuid,
219-
) -> anyhow::Result<Option<FallbackSession>> {
220-
let mut redis = ctx.redis().await?;
221-
let session: Option<Json<FallbackSession>> = redis
222-
.hget(FALLBACK_SESSIONS_KEY, session_id.to_string())
223-
.await?;
224-
Ok(session.map(Json::into_inner))
225-
}
226-
227-
pub async fn delete_fallback<C: Context>(ctx: &C, session: FallbackSession) -> anyhow::Result<()> {
228-
let mut redis = ctx.redis().await?;
229-
let id_key = make_fallback_user_id_key(session.user_id);
230-
let name_key = make_fallback_username_key(&session.username);
231-
let channels_key = make_fallback_channels_key(&session.token_id);
232-
let spectators_key = make_fallback_spectators_key(&session.token_id);
233-
let streams_key = make_fallback_streams_key(&session.token_id);
234-
let stream_offsets_key = make_fallback_stream_offsets_key(&session.token_id);
235-
let user_stream_key = make_fallback_user_stream_key(&session.token_id);
236-
let user_stream_messages_key = make_fallback_user_stream_messages_key(&session.token_id);
237-
let msg_history_key = make_fallback_message_history_key(&session.token_id);
238-
let afk_msgs_key = make_fallback_sent_away_messages_key(&session.token_id);
239-
let processing_lock_key = make_fallback_processing_lock_key(&session.token_id);
240-
redis::pipe()
241-
.atomic()
242-
.hdel(FALLBACK_SESSIONS_KEY, session.token_id)
243-
.ignore()
244-
.del(id_key)
245-
.ignore()
246-
.del(name_key)
247-
.ignore()
248-
.del(channels_key)
249-
.ignore()
250-
.del(spectators_key)
251-
.ignore()
252-
.del(streams_key)
253-
.ignore()
254-
.del(stream_offsets_key)
255-
.ignore()
256-
.del(user_stream_key)
257-
.ignore()
258-
.del(user_stream_messages_key)
259-
.ignore()
260-
.del(msg_history_key)
261-
.ignore()
262-
.del(afk_msgs_key)
263-
.ignore()
264-
.del(processing_lock_key)
265-
.ignore()
266-
.exec_async(redis.deref_mut())
267-
.await?;
268-
Ok(())
269-
}

0 commit comments

Comments
 (0)