Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #287 from orbitdb/feat/optional-pin
Browse files Browse the repository at this point in the history
add pin option
  • Loading branch information
haadcode authored Nov 29, 2019
2 parents cacf2df + 95154b4 commit 2e95856
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion benchmarks/benchmark-append.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let queriesPerSecond = 0
let lastTenSeconds = 0

const queryLoop = async () => {
await log.append(totalQueries.toString())
await log.append(totalQueries.toString(), 1, false)
totalQueries++
lastTenSeconds++
queriesPerSecond++
Expand Down
39 changes: 27 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"json-stringify-deterministic": "^1.0.1",
"multihashing-async": "^0.7.0",
"orbit-db-identity-provider": "orbitdb/orbit-db-identity-provider#feat/cache",
"orbit-db-io": "orbitdb/orbit-db-io",
"orbit-db-io": "github:orbitdb/orbit-db-io#feat/pin",
"p-do-whilst": "^1.1.0",
"p-each-series": "^2.1.0",
"p-map": "^1.1.1",
Expand Down
8 changes: 4 additions & 4 deletions src/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Entry {
* console.log(entry)
* // { hash: null, payload: "hello", next: [] }
*/
static async create (ipfs, identity, logId, data, next = [], clock, refs = []) {
static async create (ipfs, identity, logId, data, next = [], clock, refs = [], pin) {
if (!isDefined(ipfs)) throw IpfsNotDefinedError()
if (!isDefined(identity)) throw new Error('Identity is required, cannot create entry')
if (!isDefined(logId)) throw new Error('Entry requires an id')
Expand All @@ -49,7 +49,7 @@ class Entry {
entry.key = identity.publicKey
entry.identity = identity.toJSON()
entry.sig = signature
entry.hash = await Entry.toMultihash(ipfs, entry)
entry.hash = await Entry.toMultihash(ipfs, entry, pin)

return entry
}
Expand Down Expand Up @@ -93,13 +93,13 @@ class Entry {
* // "Qm...Foo"
* @deprecated
*/
static async toMultihash (ipfs, entry) {
static async toMultihash (ipfs, entry, pin = false) {
if (!ipfs) throw IpfsNotDefinedError()
if (!Entry.isEntry(entry)) throw new Error('Invalid object format, cannot generate entry hash')

// // Ensure `entry` follows the correct format
const e = Entry.toEntry(entry)
return io.write(ipfs, getWriteFormat(e.v), e, { links: IPLD_LINKS })
return io.write(ipfs, getWriteFormat(e.v), e, { links: IPLD_LINKS, pin })
}

static toEntry (entry, { presigned = false, includeHash = false } = {}) {
Expand Down
5 changes: 3 additions & 2 deletions src/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class Log extends GSet {
* @param {Entry} entry Entry to add
* @return {Log} New Log containing the appended value
*/
async append (data, pointerCount = 1) {
async append (data, pointerCount = 1, pin = false) {
// Update the clock (find the latest clock)
const newTime = Math.max(this.clock.time, this.heads.reduce(maxClockTimeReducer, 0)) + 1
this._clock = new Clock(this.clock.id, newTime)
Expand Down Expand Up @@ -297,7 +297,8 @@ class Log extends GSet {
data,
nexts,
this.clock,
refs
refs,
pin
)

const canAppend = await this._access.canAppend(entry, this._identity.provider)
Expand Down

0 comments on commit 2e95856

Please sign in to comment.