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

Now store the session as JSON. #4829

Merged
merged 4 commits into from
Feb 5, 2024
Merged

Conversation

seanparsons
Copy link
Contributor

Problem:
Our server serialises the content of the session with a binary serialisation which means that it's difficult for anything else to look into the content of that session even if it has access to the database.

Fix:
This adds an additional column session_json to the persistent_session table, which is populated at these points:

  • When the session is created.
  • When the session is updated.
  • When a lookup is made against the session and if the session_json column is NULL.

The session_json column is stored as the PostgreSQL native jsonb type which means it can be manipulated directly in PostgreSQL itself, rather than being stored as a text type.

Commit Details:

  • Add a session_json column to persistent_session.
  • PersistentSessionFields now includes the type for session_json.
  • sessionToTable now takes a value of type Value to populate the session_json column with.
  • Added sessionMapToJSON to validate the SessionMap value we expect as well as to construct the JSON that goes into session_json.
  • lookupSession backfills the session_json column if it is NULL.
  • insertSession and replaceSession functions of the Storage SessionStorage instance now streamline in a value for the session_json column.

- Add a `session_json` column to `persistent_session`.
- `PersistentSessionFields` now includes the type for `session_json`.
- `sessionToTable` now takes a value of type `Value` to populate the
  `session_json` column with.
- Added `sessionMapToJSON` to validate the `SessionMap` value we expect
  as well as to construct the JSON that goes into `session_json`.
- `lookupSession` backfills the `session_json` column if it is null.
- `insertSession` and `replaceSession` functions of the `Storage SessionStorage`
  instance now streamline in a value for the `session_json` column.
@seanparsons seanparsons changed the title feature(server) Now store the session as JSON. Now store the session as JSON. Feb 2, 2024
Copy link
Contributor

github-actions bot commented Feb 2, 2024

Try me

Copy link

relativeci bot commented Feb 2, 2024

Job #10216: Bundle Size — 62.34MiB (~-0.01%).

2e283cb(current) vs 794431b master#10213(baseline)

Warning

Bundle contains 66 duplicate packages – View duplicate packages

Bundle metrics  Change 2 changes Regression 1 regression
                 Current
Job #10216
     Baseline
Job #10213
Regression  Initial JS 35.38MiB(~+0.01%) 35.38MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 20.22% 21.79%
No change  Chunks 28 28
No change  Assets 32 32
No change  Modules 4407 4407
No change  Duplicate Modules 490 490
No change  Duplicate Code 30.7% 30.7%
No change  Packages 462 462
No change  Duplicate Packages 65 65
Bundle size by type  Change 2 changes Regression 1 regression Improvement 1 improvement
                 Current
Job #10216
     Baseline
Job #10213
Regression  JS 62.33MiB (~+0.01%) 62.33MiB
Improvement  HTML 11.37KiB (-0.32%) 11.41KiB

View job #10216 reportView feature/session-stored-as-json branch activityView project dashboard

Copy link
Contributor

@ruggi ruggi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if we should make the new column not nullable for consistency
(alter table ... add column session_json jsonb not null default '{}') but I think it's fine this way.

Copy link
Contributor

github-actions bot commented Feb 2, 2024

Performance test results:
(Chart1)
(Chart2)

@seanparsons seanparsons merged commit ceedc4a into master Feb 5, 2024
12 checks passed
@seanparsons seanparsons deleted the feature/session-stored-as-json branch February 5, 2024 12:08
@ruggi ruggi mentioned this pull request Feb 8, 2024
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.

3 participants