|
1 | | -use crate::common::chat; |
2 | 1 | use crate::common::chat::safe_username; |
3 | | -use crate::common::context::{Context, PoolContext}; |
| 2 | +use crate::common::context::Context; |
4 | 3 | use crate::common::redis_json::Json; |
5 | | -use crate::entities::sessions::{CreateSessionArgs, FallbackSession, Session}; |
| 4 | +use crate::entities::sessions::{CreateSessionArgs, Session}; |
6 | 5 | use redis::AsyncCommands; |
7 | 6 | use std::ops::DerefMut; |
8 | 7 | use uuid::Uuid; |
@@ -161,109 +160,3 @@ pub async fn set_private_dms<C: Context>( |
161 | 160 | session.private_dms = private_dms; |
162 | 161 | update(ctx, session).await |
163 | 162 | } |
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