litexplore icon indicating copy to clipboard operation
litexplore copied to clipboard

Create configuration screen

Open polyrand opened this issue 3 years ago • 1 comments

This will let users configure some parts of the UI like the number of rows shown by default.

polyrand avatar Jun 23 '22 11:06 polyrand

The configuration will be saved in a cookie as a JSON object. Should I compress the JSON string. Some testing:

import gzip
import base64
import json

data = {
    "max_rows": 10,
    "sqlite_bin_paths": ["/usr/bin/sqlite3", "/home/ubuntu/.bin/sqlite3"],
    "recent_dbs": ["/home/ubuntu/data.db", "/home/ubuntu/app/data.db"],
    "ssh_key": "~/.ssh/id_rsa",
}

data_2 = {
    "max_rows": 10,
    "sqlite_bin_paths": ["/usr/bin/sqlite3", "/home/ubuntu/.bin/sqlite3"],
    "recent_dbs": ["/home/ubuntu/data.db", "/home/ubuntu/app/data.db"],
    "ssh_key": "~/.ssh/id_rsa",
    "foo_max_rows": 10,
    "foo_sqlite_bin_paths": ["/usr/bin/sqlite3", "/home/ubuntu/.bin/sqlite3"],
    "foo_recent_dbs": ["/home/ubuntu/data.db", "/home/ubuntu/app/data.db"],
    "foo_ssh_key": "~/.ssh/id_rsa",
    "bar_max_rows": 10,
    "bar_sqlite_bin_paths": ["/usr/bin/sqlite3", "/home/ubuntu/.bin/sqlite3"],
    "bar_recent_dbs": ["/home/ubuntu/data.db", "/home/ubuntu/app/data.db"],
    "bar_ssh_key": "~/.ssh/id_rsa",
}


raw_data = json.dumps(data).encode()
# raw_data = json.dumps(data_2).encode()

print(f"Raw data: {len(raw_data)}")

compressed_data = gzip.compress(raw_data)

print(f"Compressed data: {len(compressed_data)}")

compressed_b64 = base64.b64encode(compressed_data)

print(f"Compressed b64: {len(compressed_b64)}")

With data:

Raw data: 183
Compressed data: 136
Compressed b64: 184

With data_2:

Raw data: 581
Compressed data: 175
Compressed b64: 236

With a small configuration mapping, it doesn't make much sense to compress it. It would make debugging harder and add overhead. But when the mapping grows (data_2) it may be worth compressing the data.

Note: the sample data is biased, data_2 has a lot of repeating patterns. This favors the compression, but with different data the results may not be as good.

polyrand avatar Jan 05 '23 11:01 polyrand