AdguardTeam / AdguardTeam/AdGuardHome

ETag comparison

Open
#7,050 1 comment 1 reaction 0 assignees View on GitHub
enhancement performance
Dominant language
TypeScript
Stars
36.9k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

### Prerequisites

- [X] I have checked the [Wiki](https://github.com/AdguardTeam/AdGuardHome/wiki) and [Discussions](https://github.com/AdguardTeam/AdGuardHome/discussions) and found no answer

- [X] I have searched other issues and found no duplicates

- [X] I want to request a feature or enhancement and not ask a question

### The problem

High bandwidth usage if big filter lists get updated frequently.

### Proposed solution

Compare the ETag of the local filter file with the one on the server before downloading.

### Alternatives considered and additional information

I update filters with curl now because it also uses way less RAM and IO.
Example (thx to ChatGPT):

```
#!/bin/bash

# URL of the file to download
URL="https://example.txt"

# Local file to save the downloaded content
LOCAL_FILE="/mnt/example.txt"

# File to store the ETag
ETAG_FILE="/mnt/etagexample.txt"

# Function to download the file
download_file() {
echo "Downloading file..."
curl -o "$LOCAL_FILE" -D - "$URL" | grep -i etag > "$ETAG_FILE"
}

# Check if the ETag file exists
if [ -f "$ETAG_FILE" ]; then
# Get the saved ETag
SAVED_ETAG=$(cat "$ETAG_FILE" | awk -F'"' '/etag/ {print $2}')

# Make a HEAD request to get the current ETag from the server
CURRENT_ETAG=$(curl -I "$URL" 2>/dev/null | grep -i etag | awk -F'"' '/etag/ {print $2}')

# Compare the ETags
if [ "$SAVED_ETAG" != "$CURRENT_ETAG" ]; then
echo "ETag has changed. Downloading new file..."
download_file
else
echo "ETag has not changed. No download needed."
fi
else
echo "No previous ETag found. Downloading file..."
download_file
fi
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.