Open criccomini opened 4 years ago
Alternatively, you could cache the static HTML, with a 30s timeout, or something.
Something like this might be a quick hack:
https://www.npmjs.com/package/read-last-lines
Stick that at the end of handleAllURLs
and read the last 100 lines from the file. You can even reverse lines
while you're at it, so you don't need to unshift later.
https://roguestockbot.com/stock-updates is very slow right now. It's taking more than 14 seconds to load. Most of the time is spent in /stock-updates. This code is inefficient:
https://github.com/jonniechow/RogueStockBot/blob/master/app.js#L627-L648
There are a few things going on here that are slow:
|
and once on,
. String splits are slow.Most of this work appears to be throw-away. Only the last 100 items appear to be used (the first 100, after unshifting). There is no pagination either.
This code can be improved in a number of ways. A short term fix would be to trim the stock-log.txt file to just the last 100 lines, though. I took a look, and it appears that the file grows indefinitely. As it grows, the site will get slower and slower as each page refresh will parse all lines in the txt file.