Skip to content

Conversation

@erming
Copy link
Contributor

@erming erming commented Aug 23, 2021

Hello maintainers,

While using this plugin with the https://github.com/eta-dev/eta template engine, I noticed that NODE_ENV=production never cached the templates.

After some digging I found the culprit:

  • point-of-view never sends the { cache: true } option to the eta engine

This pull request solves this.

app.register(require("point-of-view"), {
  engine: {
    eta: require("eta")
  },
  options: {
    cache: true // This variable is now set by NODE_ENV=production
  }
});

It can also be enabled by passing production: true to the engine.

Benchmark

Rendering a simple template with NODE_ENV=production

// index.js
app.register(require("point-of-view"), {
  engine: {
    eta: require("eta")
  }
});
app.get("/", async (req, res) => {
  res.view("view", {
    items: ["a", "b", "c"]
  });
});

// view.eta
<ul class="items">
  <% for (let item of it.items) { %>
    <li><%= item %></li>
  <% } %>
</ul>

Performance improvements:

$ autocannon -c 100 -d 5 -p 10 localhost:8000

— Before:   32k requests in 5.03s,  7.4 MB read
— After:   252k requests in 5.03s, 60.4 MB read

Checklist

@Fdawgs
Copy link
Member

Fdawgs commented Aug 23, 2021

LGTM.

For reference for other reviewers: https://eta.js.org/docs/api/configuration

Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test like this one to verify this new default value?

test('fastify.view with eta engine and custom cache', t => {

@erming
Copy link
Contributor Author

erming commented Aug 24, 2021

Could you add a test like this one to verify this new default value?

test('fastify.view with eta engine and custom cache', t => {

Done!

@climba03003 climba03003 requested a review from Eomm August 25, 2021 07:02
Copy link
Member

@climba03003 climba03003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants