Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Multidat #198

Merged
merged 1 commit into from
Feb 10, 2017
Merged

Multidat #198

merged 1 commit into from
Feb 10, 2017

Conversation

yoshuawuyts
Copy link
Contributor

@yoshuawuyts yoshuawuyts commented Feb 4, 2017

This touches some of the same code as #173. I think once this patch is merged we can move to some of the ergonomics #173 provides (e.g. using getters and the like for state access). This patch should provide us with some robust underpinnings to work on top ✨

changes

  • removes all dependencies on level which preps us for the upcoming SLEEP release
  • moved state into ~/.dat-desktop-db.json using toiletdb
  • renamed some methods on model/repos to be more in line with the dat cli
  • moved our custom dat management code into multidat library. It's fully tested to make sure it works as expected and relies on multidrive and the latest dat-node
  • made all unhandled errors call back instead. Might lead to crashes where errors were previously swallowed
  • added a test to catch unused deps
  • removed a whole bunch of unused deps
  • removed more code than was added which is always 🆒

todo

notes

  • placing this under the public launch milestone because moving off level should be done sooner rather than later
  • I thought Upgrade to dat-node@1. Fixes #168 #173 was merged already before submitting this PR; apologies that there's some overlap there!
  • during the writing of this patch we found a few subtle bugs in dat-node; they're solved now but we'll probably run into more
  • there's less DB lock errors it seems, but we're hitting different state corruptions now; I think we'll need to focus on debugging for the next week or so to have it stable enough for a release

@yoshuawuyts yoshuawuyts self-assigned this Feb 4, 2017
@yoshuawuyts yoshuawuyts added this to the Public Launch milestone Feb 4, 2017
Copy link
Collaborator

@juliangruber juliangruber left a comment

Choose a reason for hiding this comment

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

..otherwise, NIIIICE!

const fs = require('fs')

const argv = minimist(remoteProcess.argv.slice(2))
const rootDir = argv.data || `${app.getPath('downloads')}/dat`
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we add this back? this is required so you can run two instances of dat-desktop on the same machine, to verify they're able to replicate with each other properly

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 yeah sounds good - we should probably come up with a better way to handle options later, but re-adding ✨

Copy link
Collaborator

Choose a reason for hiding this comment

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

the mkdirSync is missing still. why not just add back this file as a whole?

models/repos.js Outdated
var dblocation = path.join(process.env.HOME)
var dbfile = path.join(dblocation, '.dat-desktop-db.json')

var arr = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

this variable name is a bit generic, can we change this to waterfall([fun... or var tasks?

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 yeah, I like tasks!

models/repos.js Outdated
}), 1500, true)
// boot multidat, create the ~/Downloads/dat directory
function startMultidat (send, done) {
var dblocation = path.join(process.env.HOME)
Copy link
Collaborator

Choose a reason for hiding this comment

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

should be camelCased, to be consistent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aye

models/repos.js Outdated
function (next) {
mkdirp(dblocation, next)
},
function (val, next) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

we're not using val, can you rename it to _?
also the val below would be more clear when renamed to multidat, as that's the identifier used below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup!

models/repos.js Outdated
function removeDat (state, data, send, done) {
assert.ok(data.key, 'repos-model.deleteDat: data.key should exist')

if (data.confirmed === true) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

because the case where data.confirmed === false always happens first, can we list it first here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yeah, nice one (:

}

function cloneDat (state, data, send, done) {
assert.ok(Buffer.isBuffer(data) || typeof data === 'string', 'repos-model.cloneDat: data should be a buffer or a string')
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is taken care of by dat-encoding

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not necessarily - if undefined is passed for example we'll get a weird error somewhere down in a package - this guards against that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(hope you ok with this? - I know I use assert a lot, but feel we're still at a spot where we regularly get weird errors that having lots of asserts can help us catch and trace bugs better)

Copy link
Collaborator

Choose a reason for hiding this comment

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

dat-encoding has sufficient guards now too, see https://github.com/juliangruber/dat-encoding/blob/master/index.js, but i'm also ok with leaving this here, for extra clarity

function cloneDat (state, data, send, done) {
assert.ok(Buffer.isBuffer(data) || typeof data === 'string', 'repos-model.cloneDat: data should be a buffer or a string')

var key = encoding.decode(data).toString('hex')
Copy link
Collaborator

Choose a reason for hiding this comment

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

can be refactored to var key = encoding.toStr(data)

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 nice!

@@ -7,45 +7,37 @@
"description": "Dat Desktop App",
"author": "Dat Team",
"dependencies": {
"aliasify": "^2.1.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks for cleaning this up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

:D

@yoshuawuyts
Copy link
Contributor Author

@juliangruber doneeeeee ✨

models/repos.js Outdated
@@ -195,6 +195,14 @@ function createManager (multidat, onupdate) {
var stats = dat.trackStats()
dat.stats = stats

multidat.readManifest(dat, function (_, manifest) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

looks like this fn is only called once, however the metadata should update whenever the dat.json changes

@yoshuawuyts yoshuawuyts force-pushed the multidat branch 2 times, most recently from c7e8631 to aa9e16f Compare February 8, 2017 04:06
@@ -196,12 +194,15 @@ function tableElement (dats, send) {
// ([obj], fn) -> html
function createTable (dats, send) {
return dats.map(dat => {
const progress = dat.stats.blocksTotal
? Math.round(dat.stats.blocksProgress / dat.stats.blocksTotal * 100)
const stats = dat.stats && dat.stats.get()
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't dat.stats always be set? also, this getter was more convenient to use: https://github.com/datproject/dat-desktop/pull/198/files#diff-66caf64acff533dbfc525b13489309cdL178

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not a fan of getters / setters / proxies as an API b/c it hides what's going on; but yeah think you're right - it's set always now; was being somewhat defensive (:

Copy link
Collaborator

@juliangruber juliangruber Feb 8, 2017

Choose a reason for hiding this comment

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

yeah, there's a balance with defensive programming and it's not easy to determine. however since we know there's always dat.stats, it's clearer this way. Otherwise you can read the code above and think otherwise.

Not programming defensively also speaks.

const progress = dat.stats.blocksTotal
? Math.round(dat.stats.blocksProgress / dat.stats.blocksTotal * 100)
const stats = dat.stats && dat.stats.get()
const progress = (stats)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are you adding parens around single values? precedence over the identity is always true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

const progress = stats looks like an assignment without parens imo; always write my ternaries / arrow functions with parens; helps with readability

Copy link
Collaborator

Choose a reason for hiding this comment

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

const progress = (stats) can be an assignment too though :P

Copy link
Collaborator

Choose a reason for hiding this comment

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

My main point with style is just that it should be consistent over the whole project. Either stick to the existing style, or make the rest of the code base follow along in an atomic step.

const fs = require('fs')

const argv = minimist(remoteProcess.argv.slice(2))
const rootDir = argv.data || `${app.getPath('downloads')}/dat`
Copy link
Collaborator

Choose a reason for hiding this comment

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

the mkdirSync is missing still. why not just add back this file as a whole?

models/repos.js Outdated
})
})
function createModel () {
var manager = null
Copy link
Collaborator

Choose a reason for hiding this comment

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

let

models/repos.js Outdated

var tasks = [
function (next) {
mkdirp(dbLocation, next)
Copy link
Collaborator

Choose a reason for hiding this comment

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

process.env.HOME always exists, no need to mkdirp it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point

models/repos.js Outdated
mkdirp(dbLocation, next)
},
function (_, next) {
var db = toilet(dbFile)
Copy link
Collaborator

Choose a reason for hiding this comment

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

const

}

function cloneDat (state, data, send, done) {
assert.ok(Buffer.isBuffer(data) || typeof data === 'string', 'repos-model.cloneDat: data should be a buffer or a string')
Copy link
Collaborator

Choose a reason for hiding this comment

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

dat-encoding has sufficient guards now too, see https://github.com/juliangruber/dat-encoding/blob/master/index.js, but i'm also ok with leaving this here, for extra clarity

${confirmModal(() => send('repos:deleteConfirm', link))}
${confirmModal(() => send('repos:remove', {
confirmed: true,
key: link
Copy link
Collaborator

Choose a reason for hiding this comment

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

having key and link makes this confusing, do you think we can get it to just use one term across the codebase?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 I'm guilty of this too in the CLI.

In my mind key the 64 character hash (mostly as a buffer), without any other characters. link is any think that contains a key (or references one), e.g. dat://<key>, datproject.org/view/<key>, datproject.org/karissa/more-tweets-more-votes (which resolves a key via API). Though I mostly refer to all of these as key in the CLI.

But we should decide on a consistent terminology.

fixup! more stuff

fixup! fix bugggssss

fixup! finish like most of this stuff

fixup! rm unused deps

fixup! default progress to 0

setup metadata

add @juliangruber's feedback
@yoshuawuyts
Copy link
Contributor Author

just arrived at a place with internet so pushed final changes based on comments you made; tried pushing yest but somehow github wouldn't let me. Should be all good now I think - feel free to merge.

Big warning on that this might cause all sorts of bugs to pop up b/c we're handling more errors now; if you folks could go ahead and test things that'd be very valuable I reckon. Cheers!

@juliangruber
Copy link
Collaborator

you force pushed over commits i added to this branch, that's why github didn't let you

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants