Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETag comparison #7050

Open
3 tasks done
GrumpyGiuseppe opened this issue Jun 1, 2024 · 0 comments
Open
3 tasks done

ETag comparison #7050

GrumpyGiuseppe opened this issue Jun 1, 2024 · 0 comments
Labels
enhancement performance Issues about performance and resource consumption

Comments

@GrumpyGiuseppe
Copy link

Prerequisites

  • I have checked the Wiki and Discussions and found no answer

  • I have searched other issues and found no duplicates

  • 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
@ainar-g ainar-g added enhancement performance Issues about performance and resource consumption and removed feature request labels Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement performance Issues about performance and resource consumption
Projects
None yet
Development

No branches or pull requests

2 participants