feat: batch favorites endpoint + frontend dedup fixes

Backend:
- Add POST /api/favorites/batch endpoint (single multi-row INSERT)
- Add BatchFavoritesResult/BatchFavoritesStats DTOs
- Add batch methods to ports, service, PG repository
- Transaction-based insert with ON CONFLICT DO NOTHING, chunking at 5000

Frontend:
- Rewrite batchFavorites() to single API call (40 requests → 1)
- Add _replaceCacheFromResponse() to avoid extra GET round-trip
- Centralize formatFileSize, isTextViewable, formatDateTime, formatDateShort
- Remove duplicate icon mapping from app.js
- Fix inconsistent quota defaults (10GB everywhere)
This commit is contained in:
Dionisio
2026-02-16 09:17:54 +01:00
parent fb652c07e3
commit d6c4eb884d
17 changed files with 433 additions and 141 deletions
+17 -1
View File
@@ -1,4 +1,4 @@
use crate::application::dtos::favorites_dto::FavoriteItemDto;
use crate::application::dtos::favorites_dto::{BatchFavoritesResult, FavoriteItemDto};
use crate::common::errors::Result;
use async_trait::async_trait;
@@ -21,6 +21,14 @@ pub trait FavoritesUseCase: Send + Sync {
/// Check if an item is in user's favorites
async fn is_favorite(&self, user_id: &str, item_id: &str, item_type: &str) -> Result<bool>;
/// Add multiple items to favorites in a single transaction.
/// Returns enriched favourites list so the client can replace its cache.
async fn batch_add_to_favorites(
&self,
user_id: &str,
items: &[(String, String)],
) -> Result<BatchFavoritesResult>;
}
// ─────────────────────────────────────────────────────
@@ -45,4 +53,12 @@ pub trait FavoritesRepositoryPort: Send + Sync + 'static {
/// Checks if an item is in favorites.
async fn is_favorite(&self, user_id: &str, item_id: &str, item_type: &str) -> Result<bool>;
/// Insert multiple items in a single transaction.
/// Returns the number of rows actually inserted (ignoring duplicates).
async fn add_favorites_batch(
&self,
user_id: &str,
items: &[(String, String)],
) -> Result<u64>;
}