fmeringdal / nettu-scheduler

A self-hosted calendar and scheduler server.
MIT License
535 stars 27 forks source link

`metadata` storage is not safe #18

Closed omid closed 3 years ago

omid commented 3 years ago

The current metadata storage is not safe.

Currently, key and value is _ separated and it's easily breakable if we have _ in the key. My suggestion is to use JSONB for the DB type and use serde to (de)serialize it.

fmeringdal commented 3 years ago

Yeah, I though I had documented somewhere that metadata keys cannot contain _, but apparently not. Another alternative is to have a more unusual separator, and reject metadata keys that contain that separator. Your solution should probably work as well, what kind of index should then be used for querying on JSONB?

omid commented 3 years ago

JSONB is quite fast. For key/value scenario, a simple GIN index is enough.

Based on this link, this index is enough: CREATE INDEX myindex ON mytable USING GIN (mycolumn jsonb_path_ops) or to stand in a more safe side, we can use: CREATE INDEX myindex ON mytable USING GIN (mycolumn)

And we can query like this: SELECT * FROM mytable WHERE mycolumn @> '{"key": "value"}'

fmeringdal commented 3 years ago

Nice, then I think that is what we should go for! I can change it within this week if you have not already started on this :)

omid commented 3 years ago

Then I'll do it :) I'm in the middle of it :P

omid commented 3 years ago

seems like I cannot assign issues to myself, you can assign this one to me

fmeringdal commented 3 years ago

I invited you as a collaborator on the project now, then you should have more access :)