Skip to content

Implement idempotent UUID generation based on content and website ver…#456

Merged
seansica merged 1 commit into
developfrom
455-bug-excessive-indexeddb-storage-usage-due-to-frequent-uuid-generation-on-rapid-deployments
Aug 30, 2023
Merged

Implement idempotent UUID generation based on content and website ver…#456
seansica merged 1 commit into
developfrom
455-bug-excessive-indexeddb-storage-usage-due-to-frequent-uuid-generation-on-rapid-deployments

Conversation

@seansica

Copy link
Copy Markdown
Contributor

Description of what has changed

Changed the UUID generation logic to use CONTENT_VERSION and WEBSITE_VERSION as seeds for idempotent UUID creation. This ensures consistent UUIDs for the same content and website versions, optimizing storage usage and preventing the creation of redundant IndexedDB tables.

Issues addressed by pull request

Closes #455.

Testing

UUID idempotence was tested with the following script:

import hashlib

def generate_uuid_from_seeds(content_version, website_version):
    """
    Generate a UUID based on the given content_version and website_version.
    
    Args:
    - content_version (str): Semantic version of the content without a leading 'v'.
    - website_version (str): Semantic version of the website with a leading 'v'.

    Returns:
    - str: A UUID generated based on the two versions.
    """
    # Combine and hash the values
    seed = f"{content_version}-{website_version}".encode('utf-8')
    hashed_seed = hashlib.md5(seed).hexdigest()

    # Convert the first 32 characters of the hash to a UUID format
    return '-'.join([hashed_seed[i:i+length] for i, length in zip([0, 8, 12, 16, 20], [8, 4, 4, 4, 12])])


def test_uuid_idempotency():
    """
    Test the idempotency of the UUID generation.
    """
    test_pairs = [
        ("4.0.4", "v13.1"),
        ("4.0.5", "v13.2"),
        ("5.0.0", "v14.0")
    ]

    for content, website in test_pairs:
        first_uuid = generate_uuid_from_seeds(content, website)
        second_uuid = generate_uuid_from_seeds(content, website)
        
        assert first_uuid == second_uuid, f"UUIDs for {content}-{website} are not idempotent."
        print(f"UUID for {content}-{website}: {first_uuid}")

if __name__ == "__main__":
    test_uuid_idempotency()

Output:

❯ python3 test_uuid.py
UUID for 4.0.4-v13.1: 112d7f46-f2b7-3723-0d6d-f9d1938c70e6
UUID for 4.0.5-v13.2: c42f3ff0-edc1-63d5-ce44-43662b9e4939
UUID for 5.0.0-v14.0: 54e7ea6c-81c0-c8a4-50aa-ba42449be348

@seansica seansica requested a review from jondricek August 30, 2023 20:07
@seansica seansica self-assigned this Aug 30, 2023
@sonarqubecloud

Copy link
Copy Markdown

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 1 Security Hotspot
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@seansica seansica merged commit c3b532f into develop Aug 30, 2023
@seansica seansica deleted the 455-bug-excessive-indexeddb-storage-usage-due-to-frequent-uuid-generation-on-rapid-deployments branch August 30, 2023 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant