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

UserContext inits evey rest call #149

Open
gavr123456789 opened this issue Jan 19, 2022 · 4 comments
Open

UserContext inits evey rest call #149

gavr123456789 opened this issue Jan 19, 2022 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@gavr123456789
Copy link

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 #137

@ringabout
Copy link
Member

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.

@gavr123456789
Copy link
Author

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

@ringabout ringabout added the help wanted Extra attention is needed label Jan 20, 2022
@gavr123456789
Copy link
Author

gavr123456789 commented Jan 21, 2022

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

@PhilippMDoerner
Copy link
Contributor

PhilippMDoerner commented Mar 13, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants