Skip to content

raw_json: store byte arrays as base64 #86

Closed

Description

@neoromantic

mtcute gives byte fields (fileReference, a photo's stripped thumbnail and others) as Uint8Array, and JSON.stringify writes each one as an object with a key per byte. A made-up photo message's raw_json was about 7.7 KB for that reason; base64 took one from 7,141 to 1,330 bytes (#79). raw_json is written by several paths (history pages, live updates, tg send, chats and users), each with its own JSON.stringify.

Proposed:

  • One serializer for every raw_json write: bigint as a string (as most paths do today) and Uint8Array as a base64 string.
  • New and re-fetched rows use it. Rows already cached stay as they are until a background re-encode exists (see the follow-up on background migrations).
  • The stripped thumbnail stays in raw_json: once a message is deleted on Telegram, it is the only trace of the picture.
  • docs/database-schema.md says how byte fields are stored, so tg sql users can read them with json_extract.

Done when every raw_json write goes through the serializer, a test checks a made-up photo message's size and its base64 fields, and the docs and changelog describe it. Related: #80.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions