Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Implement favicon deduplication locally to all clients (#1473)

Leendert de Borst75898daed8ac
diff --git a/apps/mobile-app/app/(tabs)/items/add-edit.tsx b/apps/mobile-app/app/(tabs)/items/add-edit.tsx
index b709b5c27..87a202059 100644
--- a/apps/mobile-app/app/(tabs)/items/add-edit.tsx
+++ b/apps/mobile-app/app/(tabs)/items/add-edit.tsx
@@ -784,24 +784,32 @@ export default function AddEditItemScreen(): React.ReactNode {
const urlString = Array.isArray(urlValue) ? urlValue[0] : urlValue;
const shouldFetchFavicon = urlString && urlString !== 'https://' && urlString !== 'http://';
- if (shouldFetchFavicon) {
- // Only show loading indicator when fetching favicon
- setIsSaving(true);
- setSaveStatus(t('vault.savingChangesToVault'));
+ if (shouldFetchFavicon && dbContext.sqliteClient) {
+ // Extract source domain for deduplication check
+ const source = dbContext.sqliteClient.logos.extractSourceFromUrl(urlString);
- try {
- const timeoutPromise = new Promise((_, reject) =>
- setTimeout(() => reject(new Error('Favicon extraction timed out')), 5000)
- );
+ // Only fetch favicon if no logo exists for this source (deduplication)
+ const hasExistingLogo = source !== 'unknown' && await dbContext.sqliteClient.logos.hasLogoForSource(source);
+
+ if (!hasExistingLogo) {
+ // Only show loading indicator when fetching favicon
+ setIsSaving(true);
+ setSaveStatus(t('vault.savingChangesToVault'));
+
+ try {
+ const timeoutPromise = new Promise((_, reject) =>
+ setTimeout(() => reject(new Error('Favicon extraction timed out')), 5000)
+ );
- const faviconPromise = webApi.get<FaviconExtractModel>('Favicon/Extract?url=' + urlString);
- const faviconResponse = await Promise.race([faviconPromise, timeoutPromise]) as FaviconExtractModel;
- if (faviconResponse?.image) {
- const decodedImage = Uint8Array.from(Buffer.from(faviconResponse.image as string, 'base64'));
- itemToSave.Logo = decodedImage;
+ const faviconPromise = webApi.get<FaviconExtractModel>('Favicon/Extract?url=' + encodeURIComponent(urlString));
+ const faviconResponse = await Promise.race([faviconPromise, timeoutPromise]) as FaviconExtractModel;
+ if (faviconResponse?.image) {
+ const decodedImage = Uint8Array.from(Buffer.from(faviconResponse.image as string, 'base64'));
+ itemToSave.Logo = decodedImage;
+ }
+ } catch {
+ // Favicon extraction failed or timed out - not critical, continue with save
}
- } catch {
- // Favicon extraction failed or timed out - not critical, continue with save
}
}
diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor
index cf0aab36c..c51b46906 100644
--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor
+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor
@@ -391,7 +391,8 @@
}
/// <summary>
- /// Extracts favicons for credentials.
+ /// Extracts favicons for credentials. Uses domain-based deduplication to avoid
+ /// fetching the same favicon multiple times for the same domain.
/// </summary>
private async Task ExtractFaviconsForCredentials()
{
@@ -402,6 +403,10 @@
StateHasChanged();
var credentialsWithUrls = ImportedCredentials.Where(c => !string.IsNullOrEmpty(c.ServiceUrl)).ToList();
+
+ // Group credentials by normalized domain to avoid duplicate fetches
+ var processedDomains = new HashSet<string>();
+
TotalFaviconsToExtract = credentialsWithUrls.Count;
foreach (var credential in credentialsWithUrls)
@@ -411,24 +416,52 @@
break;
}
- await ExtractFaviconForCredential(credential);
+ // Extract normalized domain for deduplication
+ try
+ {
+ var domain = new Uri(credential.ServiceUrl!).Host.ToLowerInvariant();
+ if (domain.StartsWith("www."))
+ {
+ domain = domain[4..];
+ }
+
+ // Skip if we've already fetched a favicon for this domain
+ if (!processedDomains.Contains(domain))
+ {
+ processedDomains.Add(domain);
+ await ExtractFaviconForCredential(credential);
+ }
+ }
+ catch
+ {
+ // Invalid URL - skip
+ }
+
FaviconExtractionProgress++;
StateHasChanged();
}
}
/// <summary>
- /// Extracts a favicon for a credential.
+ /// Extracts a favicon for a credential. Stores by normalized domain for deduplication.
/// </summary>
/// <param name="credential">The credential to extract the favicon for.</param>
private async Task ExtractFaviconForCredential(ImportedCredential credential)
{
try
{
- var apiReturn = await HttpClient.GetFromJsonAsync<FaviconExtractModel>($"v1/Favicon/Extract?url={credential.ServiceUrl!}");
+ // Extract normalized domain for storage key
+ var domain = new Uri(credential.ServiceUrl!).Host.ToLowerInvariant();
+ if (domain.StartsWith("www."))
+ {
+ domain = domain[4..];
+ }
+
+ var apiReturn = await HttpClient.GetFromJsonAsync<FaviconExtractModel>($"v1/Favicon/Extract?url={Uri.EscapeDataString(credential.ServiceUrl!)}");
if (apiReturn?.Image is not null)
{
- ExtractedFavicons[credential.ServiceUrl!] = apiReturn.Image;
+ // Store by normalized domain for deduplication
+ ExtractedFavicons[domain] = apiReturn.Image;
}
}
catch
@@ -468,22 +501,47 @@
private async Task ProcessSingleItem(Item item)
{
var url = ItemService.GetFieldValue(item, FieldKey.LoginUrl);
- if (!string.IsNullOrEmpty(url) && ExtractedFavicons.TryGetValue(url, out var favicon))
+ if (!string.IsNullOrEmpty(url))
{
- // Store favicon in Logo entity
- var logo = new Logo
+ try
{
- Id = Guid.NewGuid(),
- Source = new Uri(url).Host,
- FileData = favicon,
- MimeType = "image/png",
- FetchedAt = DateTime.UtcNow,
- CreatedAt = DateTime.UtcNow,
- UpdatedAt = DateTime.UtcNow
- };
- var context = await DbService.GetDbContextAsync();
- context.Logos.Add(logo);
- item.LogoId = logo.Id;
+ // Extract and normalize domain for deduplication
+ var domain = new Uri(url).Host.ToLowerInvariant();
+ if (domain.StartsWith("www."))
+ {
+ domain = domain[4..];
+ }
+
+ var context = await DbService.GetDbContextAsync();
+
+ // Check if logo already exists for this source (deduplication)
+ var existingLogo = await context.Logos.FirstOrDefaultAsync(l => l.Source == domain);
+ if (existingLogo != null)
+ {
+ // Reuse existing logo
+ item.LogoId = existingLogo.Id;
+ }
+ else if (ExtractedFavicons.TryGetValue(domain, out var favicon))
+ {
+ // Create new logo from extracted favicon
+ var logo = new Logo
+ {
+ Id = Guid.NewGuid(),
+ Source = domain,
+ FileData = favicon,
+ MimeType = "image/png",
+ FetchedAt = DateTime.UtcNow,
+ CreatedAt = DateTime.UtcNow,
+ UpdatedAt = DateTime.UtcNow
+ };
+ context.Logos.Add(logo);
+ item.LogoId = logo.Id;
+ }
+ }
+ catch
+ {
+ // Invalid URL - skip logo assignment
+ }
}
await ItemService.InsertEntryAsync(item, false, false);
}
diff --git a/apps/server/AliasVault.Client/Services/ItemService.cs b/apps/server/AliasVault.Client/Services/ItemService.cs
index d89daf9fe..b10e2fdfb 100644
--- a/apps/server/AliasVault.Client/Services/ItemService.cs
+++ b/apps/server/AliasVault.Client/Services/ItemService.cs
@@ -1163,6 +1163,7 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf
/// <summary>
/// Extract favicon from service URL if available. If successful, links the item to the logo.
+ /// Checks for existing logo first to avoid unnecessary API calls (deduplication).
/// </summary>
/// <param name="item">The Item to extract the favicon for.</param>
/// <returns>Task.</returns>
@@ -1172,40 +1173,44 @@ public sealed class ItemService(HttpClient httpClient, DbService dbService, Conf
var url = GetFieldValue(item, FieldKey.LoginUrl);
if (url != null && !string.IsNullOrEmpty(url) && url != DefaultServiceUrl)
{
- // Request favicon from service URL via WebApi
try
{
- var apiReturn = await httpClient.GetFromJsonAsync<FaviconExtractModel>($"v1/Favicon/Extract?url={url}");
- if (apiReturn?.Image is not null)
+ // Extract and normalize domain for deduplication
+ var domain = new Uri(url).Host.ToLowerInvariant();
+ if (domain.StartsWith("www."))
{
- // For now, we store the favicon directly on the item's logo
- // In the future, we should use the Logo deduplication table
- var context = await dbService.GetDbContextAsync();
+ domain = domain[4..];
+ }
- // Try to find existing logo by source
- var domain = new Uri(url).Host;
- var existingLogo = await context.Logos.FirstOrDefaultAsync(l => l.Source == domain);
+ var context = await dbService.GetDbContextAsync();
- if (existingLogo != null)
- {
- item.LogoId = existingLogo.Id;
- }
- else
+ // Check if logo already exists for this source (deduplication)
+ var existingLogo = await context.Logos.FirstOrDefaultAsync(l => l.Source == domain);
+
+ if (existingLogo != null)
+ {
+ // Reuse existing logo - no need to fetch
+ item.LogoId = existingLogo.Id;
+ return;
+ }
+
+ // No existing logo - fetch from API
+ var apiReturn = await httpClient.GetFromJsonAsync<FaviconExtractModel>($"v1/Favicon/Extract?url={Uri.EscapeDataString(url)}");
+ if (apiReturn?.Image is not null)
+ {
+ // Create new logo
+ var newLogo = new Logo
{
- // Create new logo
- var newLogo = new Logo
- {
- Id = Guid.NewGuid(),
- Source = domain,
- FileData = apiReturn.Image,
- MimeType = "image/png",
- FetchedAt = DateTime.UtcNow,
- CreatedAt = DateTime.UtcNow,
- UpdatedAt = DateTime.UtcNow,
- };
- context.Logos.Add(newLogo);
- item.LogoId = newLogo.Id;
- }
+ Id = Guid.NewGuid(),
+ Source = domain,
+ FileData = apiReturn.Image,
+ MimeType = "image/png",
+ FetchedAt = DateTime.UtcNow,
+ CreatedAt = DateTime.UtcNow,
+ UpdatedAt = DateTime.UtcNow,
+ };
+ context.Logos.Add(newLogo);
+ item.LogoId = newLogo.Id;
}
}
catch