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

feat: neDB persistent datastore #48

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from

Conversation

elit-altum
Copy link
Contributor

Add neDB to create a persistent file based data store for storing runs.

@codecov
Copy link

codecov bot commented Sep 5, 2021

Codecov Report

❗ No coverage uploaded for pull request base (develop@ef1bf60). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             develop      #48   +/-   ##
==========================================
  Coverage           ?   61.67%           
==========================================
  Files              ?       19           
  Lines              ?      347           
  Branches           ?       64           
==========================================
  Hits               ?      214           
  Misses             ?      133           
  Partials           ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ef1bf60...95e1297. Read the comment docs.

@@ -3,3 +3,5 @@ node_modules/
# Prevent test coverage reports from being added
.coverage
.nyc_output

/lib/data
Copy link
Member

Choose a reason for hiding this comment

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

Are we storing the data in the project directory itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah right now we are. I'll move this to a config file.

await this.queueProcessor(item);
}, Promise.resolve());

return this.processQueue;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be a function call?

},

addEvent: async (data) => {
const batch = new BatchQueue(api.saveEvent);
Copy link
Member

Choose a reason for hiding this comment

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

We are creating a new queue every time this function is called. Is this expected? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, my bad. Should I initialize separate queues in this file and use them?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. The queue should be initialised once. Either when the file is imported or when the first call is made.

Also, do note that:

  • If multiple actions depend on each other, they should use a single queue.
  • If actions are independent but depend on multiple calls of itself, it should use a single queue.
  • If actions are not dependent on multiple calls of itself either, it doesn't need a queue.

const Table = require('./table');
const connect = require('camo').connect;
const paths = require('env-paths')('newman-dashboard');
const uri = `nedb://${paths.data}`;
Copy link
Member

Choose a reason for hiding this comment

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

Should be in config file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we create a separate PR for config files?

@@ -1,4 +1,4 @@
import store from '../state/stores/runStore';
import store from "../state/stores/runStore";
Copy link
Member

Choose a reason for hiding this comment

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

Why this change? Should we add a lint rule to always use single quotes? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is my VSCode acting up. There is a bug with the ESLint extension. 🙄

return cache[tableName];
},
// cleanup function to terminate db connection
return () => process.exit(0);
Copy link
Member

Choose a reason for hiding this comment

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

The cleanup function would terminate the whole process! Shouldn't we only close the connection?

if (index == currentQueue.length - 1) {
this.processing = false
// at last, mark processing as complete so that new batch is saved
if (index == currentQueue.length - 1) {
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: Use ===. Should enforce in eslint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, will fix this asap.


// at last, mark processing as complete so that new batch is saved
if (index == currentQueue.length - 1) {
this.processing = false;
Copy link
Member

Choose a reason for hiding this comment

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

Let it be handled on line 15. Just call this method after the reduce. It'll take care of processing the next batch. It'll keep our loop clean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh okay, I also tried that initially but thought it would lead to too many calls. Would this be a decent tradeoff?

Copy link
Member

Choose a reason for hiding this comment

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

It would be just 1 extra call, no? The benefit would be that changing the flag would be kept at a single place making it easier to read and track.

addEvent: async (data) => {
if (!data.id) throw new TypeError('Invalid id');
const run = await api.findOne(data.id);
saveEvent: async (data) => {
Copy link
Member

Choose a reason for hiding this comment

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

Let's make these methods (saveEvent and saveStats) private?

Copy link
Contributor Author

@elit-altum elit-altum Oct 14, 2021

Choose a reason for hiding this comment

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

These methods are defined in an object and not a class, can they be private as well? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Yep, just don't include them in the object. It's not using this so it doesn't need to be in the object. Just define it before the object and it should be good.

Sidenote: If it did use this, you can rename it to _saveEvent to convey the intention that it is a private method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On it @coditva, just busy with my endsems this week. Will get this done asap

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.

2 participants