Reputation: 999
I'm learning Vapor and got stuck on the proper way to interact with the server. So here's the idea of what I'm doing..
You upload a XML file to the server, it processes it, turns it to a large list of Model objects, and returns a list of json objects. Using leaf, I populate the models to a table view. example:
#loop(objects, "object") {
<tr>
<td>#(object.id)</td>
<td>#(object.name)</td>
</tr>
}
This all works file. Here's where I'm stuck. At the top of my tableview, I have some buttons that will perform actions on the objects array. ie: batch rename objects, or apply some sort of logic to them. Then I want the functionality to download the list of model objects in various formats.
I want all of this logic to live on my vapor server. Where I'm lost is how to pass this very large list back and forth with the Vapor server. Should the server be storing a list of the objects for the current web session? I looked into using Javascript in the HTML, but would I then need to parse the DOM to create my model objects. At that point, nothing would be happening in vapor. (Some of these tasks would be very server intensive.
I was looking at fluent, but then the question was would I have a database for the current session, and delete it when done? Would I be concerned with memory issues with this concept? I would think when you upload the XML, it creates a session ID, and all your requests are based off of that. Then the ID would expire at some point. This is all guessing on which would work best..
Any ideas on the best way of manipulating the vapor model objects?
Thanks!
Upvotes: 0
Views: 558
Reputation: 5421
I would think when you upload the XML, it creates a session ID, and all your requests are based off of that. Then the ID would expire at some point.
Bingo. If you are certain you want this processing to occur server-side, then you've already answered your question. You should have one database table where the model objects are stored along with a random session ID (which can be managed by Vapor using SessionsMiddleware
).
When your user has completed processing their models, you delete all objects with their session ID. You should also regularly run a scheduled job that deletes models belonging to expired sessions.
If you decide to implement user authentication, then you could use the User ID instead of the session ID.
Upvotes: 0