prologue icon indicating copy to clipboard operation
prologue copied to clipboard

UserContext inits evey rest call

Open gavr123456789 opened this issue 2 years ago • 4 comments

I added echo to the extend method, and noticed that it fires every time. This means that a new connection to mongo is opened every time. Also because of this, I can't mutate the data inside the UserContext to implement an InMemory session that uses TableRef instead of mongo.
Here my test project https://github.com/gavr123456789/full-stack-try/blob/main/backend/Nim/app.nim#L10
image I think it can be related to https://github.com/planety/prologue/issues/137

gavr123456789 avatar Jan 19 '22 00:01 gavr123456789

Yeah, I think global variables are still needed for extend. Now extend is limited to accepting no externel arguments. I think it can probably be changed into accepting a pointer from users.

ringabout avatar Jan 19 '22 00:01 ringabout

Yes, for me it looks like a pretty critical problem, it turns out state can only be stored in databases.

gavr123456789 avatar Jan 19 '22 19:01 gavr123456789

Oh, and ofc, creating new Database connection for each call is the biggest problem here. I will try use session, but I think context is more suitable place

gavr123456789 avatar Jan 21 '22 00:01 gavr123456789

@gavr123456789 I am slightly confused, isn't the extend proc being called once per request exactly what is desired? My understanding of extending context so far is, that for every request that comes in, prologues creates a Context object that it passes along and that you can modify to extend it with your own fields before it is passed along to the controller. Doing the conversion from the normal context to your custom context has to be done in a middleware and is done every request.

Is that not how it's supposed to be done? I'm pretty sure I'm having a lot of misunderstandings here, I'm just not spotting where they are.

PhilippMDoerner avatar Mar 13 '22 17:03 PhilippMDoerner