简体   繁体   English

蒸气-从HTML获取模型

[英]Vapor - Get model from HTML

I'm learning Vapor and got stuck on the proper way to interact with the server. 我正在学习Vapor,并陷入了与服务器交互的正确方法。 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. 您将XML文件上载到服务器,对其进行处理,将其转换为一大堆Model对象,然后返回json对象列表。 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. 我迷路的是如何与Vapor服务器来回传递这个非常大的列表。 Should the server be storing a list of the objects for the current web session? 服务器是否应该存储当前Web会话的对象列表? I looked into using Javascript in the HTML, but would I then need to parse the DOM to create my model objects. 我曾研究过在HTML中使用Javascript,但随后需要解析DOM来创建模型对象。 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. 我认为当您上载XML时,它会创建一个会话ID,并且所有请求都基于此。 Then the ID would expire at some point. 然后,该ID将在某个时候过期。 This is all guessing on which would work best.. 所有这些都是在猜测哪种方法最有效。

Any ideas on the best way of manipulating the vapor model objects? 关于操纵蒸气模型对象的最佳方法有什么想法吗?

Thanks! 谢谢!

I would think when you upload the XML, it creates a session ID, and all your requests are based off of that. 我认为当您上载XML时,它会创建一个会话ID,并且所有请求都基于此。 Then the ID would expire at some point. 然后,该ID将在某个时候过期。

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 ). 您应该有一个数据库表,其中存储了模型对象以及一个随机会话ID(可以由Vapor使用SessionsMiddleware对其进行管理)。

When your user has completed processing their models, you delete all objects with their session ID. 用户完成模型处理后,将删除所有具有其会话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. 如果决定实施用户身份验证,则可以使用用户ID代替会话ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM