Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter Datapod
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
Duniter Datapod
Commits
c185f112
Commit
c185f112
authored
1 year ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
c+ import as index requests
parent
317b0a1b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+2
-1
2 additions, 1 deletion
README.md
src/cesium-plus.ts
+70
-19
70 additions, 19 deletions
src/cesium-plus.ts
src/scripts/cesium-plus-import.ts
+4
-4
4 additions, 4 deletions
src/scripts/cesium-plus-import.ts
with
76 additions
and
24 deletions
README.md
+
2
−
1
View file @
c185f112
...
@@ -29,5 +29,6 @@ This will make easier to insert this data in any AMT or other data structure.
...
@@ -29,5 +29,6 @@ This will make easier to insert this data in any AMT or other data structure.
# doMergeAMT()
# doMergeAMT()
# takes about 50 seconds
# takes about 50 seconds
time
npx tsx src/scripts/cesium-plus-import.ts
time
npx tsx src/scripts/cesium-plus-import.ts
# bafyreie23z6aayg5pjrqiowwziv2zt55b3ijzch3bjf5u4ebfbjtl5raxe
# bafyreie23z6aayg5pjrqiowwziv2zt55b3ijzch3bjf5u4ebfbjtl5raxe (time)
# bafyreigif3w2js2e6xb6vrfwagig3e7oiscakr7ki5xzsngukmsorxekny (time × 1000)
```
```
This diff is collapsed.
Click to expand it.
src/cesium-plus.ts
+
70
−
19
View file @
c185f112
...
@@ -41,6 +41,16 @@ interface CplusProfileMore extends CplusProfile {
...
@@ -41,6 +41,16 @@ interface CplusProfileMore extends CplusProfile {
avatar
:
Avatar
|
CID
avatar
:
Avatar
|
CID
}
}
/// C+ profile to index request
function
cplusProfileToIndexRequest
(
profile
:
CplusProfile
,
profileCid
:
CID
):
IndexRequest
{
return
{
pubkey
:
profile
.
issuer
,
cid
:
profileCid
,
timestamp
:
profile
.
time
*
1000
,
signature
:
''
// signature is inside document for C+ data
}
}
/// adds all cids by groups ot size `groupBy`
/// adds all cids by groups ot size `groupBy`
export
async
function
processCesiumPlusImport
(
profileCids
:
CID
[],
groupBy
:
number
):
Promise
<
CID
>
{
export
async
function
processCesiumPlusImport
(
profileCids
:
CID
[],
groupBy
:
number
):
Promise
<
CID
>
{
const
rootNode
:
Array
<
Promise
<
CID
>>
=
[]
const
rootNode
:
Array
<
Promise
<
CID
>>
=
[]
...
@@ -188,30 +198,71 @@ export async function allCplusCids(cplusCID: CID): Promise<Array<[number, CID]>>
...
@@ -188,30 +198,71 @@ export async function allCplusCids(cplusCID: CID): Promise<Array<[number, CID]>>
return
Promise
.
all
(
allCIDs
)
return
Promise
.
all
(
allCIDs
)
}
}
/// import all cplus cid to AMT chunk by chunk
/// retreive all C+ data as index requests
// this allows to decrease maximum amount of concurrent connections
export
async
function
allCplusAsIndexRequestCids
(
cplusrootCID
:
CID
):
Promise
<
Array
<
[
string
,
CID
]
>>
{
// 183 seconds
export
async
function
allCplusCidsToAMTChunked
(
cplusCID
:
CID
,
rootNodeCid
:
CID
):
Promise
<
CID
>
{
console
.
log
(
Date
.
now
()
+
'
getting all cplus data
'
)
console
.
log
(
Date
.
now
()
+
'
getting all cplus data
'
)
const
cplusroot
=
await
kubo
.
dag
.
get
(
cplusCID
)
const
allCIDs
:
Array
<
Promise
<
[
string
,
CID
]
>>
=
[]
const
cplusroot
=
await
kubo
.
dag
.
get
(
cplusrootCID
)
for
(
let
chunkcid
of
cplusroot
.
value
)
{
for
(
let
chunkcid
of
cplusroot
.
value
)
{
const
allCIDs
:
Array
<
Promise
<
[
number
,
CID
]
>>
=
[]
const
chunk
=
await
kubo
.
dag
.
get
(
chunkcid
)
const
chunk
=
await
kubo
.
dag
.
get
(
chunkcid
)
for
(
let
pcid
of
chunk
.
value
)
{
for
(
let
pcid
of
chunk
.
value
)
{
const
p
=
kubo
.
dag
.
get
(
pcid
)
const
profileIR
:
Promise
<
[
string
,
CID
]
>
=
kubo
.
dag
const
profile
:
Promise
<
[
number
,
CID
]
>
=
p
.
then
((
v
)
=>
[
v
.
value
.
time
*
1000
,
pcid
])
.
get
(
pcid
)
allCIDs
.
push
(
profile
)
.
then
((
v
)
=>
cplusProfileToIndexRequest
(
v
.
value
,
pcid
))
.
then
((
r
:
IndexRequest
)
=>
Promise
.
all
([
timestampToKey
(
r
.
timestamp
),
kubo
.
dag
.
put
(
r
)]
as
[
string
,
Promise
<
CID
>
])
)
allCIDs
.
push
(
profileIR
)
}
}
}
return
Promise
.
all
(
allCIDs
)
}
// /// import all cplus cid to AMT chunk by chunk
// // this allows to decrease maximum amount of concurrent connections
// // 183 seconds
// // not optimal either
// export async function allCplusCidsToAMTChunked(cplusCID: CID, rootNodeCid: CID): Promise<CID> {
// console.log(Date.now() + ' getting all cplus data')
// const cplusroot = await kubo.dag.get(cplusCID)
// for (let chunkcid of cplusroot.value) {
// const allCIDs: Array<Promise<[number, CID]>> = []
// const chunk = await kubo.dag.get(chunkcid)
// for (let pcid of chunk.value) {
// const p = kubo.dag.get(pcid)
// const profile: Promise<[number, CID]> = p.then((v) => [v.value.time * 1000, pcid])
// allCIDs.push(profile)
// }
// const rootNode = (await kubo.dag.get(rootNodeCid)).value
// rootNodeCid = await Promise.all(allCIDs)
// .then(sortCidsAndConvertKeys)
// .then(arrayToVinode)
// .then(async (inode) => {
// // console.log(await concretizeCid(inode))
// console.log(Date.now() + ' merging')
// return mergeInodesSync(rootNode, inode)
// })
// console.log(rootNodeCid)
// }
// return rootNodeCid
// }
/// import cplus index requests to AMT
// about 90 seconds to get C+ data and convert to index requests
// about 90 seconds to merge data 1000 by 1000
export
async
function
cplusIndexRequestsToAMT
(
cplusrootCID
:
CID
,
rootNodeCid
:
CID
)
{
const
chunkSize
=
1000
console
.
log
(
'
getting all cplus index requests
'
)
const
requests
=
await
allCplusAsIndexRequestCids
(
cplusrootCID
)
requests
.
sort
()
const
n
=
requests
.
length
console
.
log
(
Date
.
now
()
+
'
merging
'
)
for
(
let
i
=
0
;
i
<
n
/
chunkSize
;
i
++
)
{
console
.
log
(
Date
.
now
()
+
'
chunk number
'
+
i
)
const
chunk
=
requests
.
slice
(
i
*
chunkSize
,
(
i
+
1
)
*
chunkSize
)
const
rootNode
=
(
await
kubo
.
dag
.
get
(
rootNodeCid
)).
value
const
rootNode
=
(
await
kubo
.
dag
.
get
(
rootNodeCid
)).
value
rootNodeCid
=
await
Promise
.
all
(
allCIDs
)
const
tree
=
arrayToVinode
(
chunk
)
// partial tree for this chunk
.
then
(
sortCidsAndConvertKeys
)
rootNodeCid
=
await
mergeInodesSync
(
rootNode
,
tree
)
.
then
(
arrayToVinode
)
console
.
log
(
'
new root node
'
+
rootNodeCid
.
toString
())
.
then
(
async
(
inode
)
=>
{
// console.log(await concretizeCid(inode))
console
.
log
(
Date
.
now
()
+
'
merging
'
)
return
mergeInodesSync
(
rootNode
,
inode
)
})
console
.
log
(
rootNodeCid
)
}
}
return
rootNodeCid
}
}
This diff is collapsed.
Click to expand it.
src/scripts/cesium-plus-import.ts
+
4
−
4
View file @
c185f112
...
@@ -5,7 +5,7 @@ import {
...
@@ -5,7 +5,7 @@ import {
allCplusCids
,
allCplusCids
,
sortCidsAndConvertKeys
,
sortCidsAndConvertKeys
,
arrayToVinode
,
arrayToVinode
,
allCplusCidsToAMTChunked
cplusIndexRequestsToAMT
}
from
'
../cesium-plus
'
}
from
'
../cesium-plus
'
import
*
as
fs
from
'
fs/promises
'
import
*
as
fs
from
'
fs/promises
'
import
{
kubo
}
from
'
../kubo
'
import
{
kubo
}
from
'
../kubo
'
...
@@ -77,11 +77,11 @@ async function doMergeAMT() {
...
@@ -77,11 +77,11 @@ async function doMergeAMT() {
// doMergeAMT()
// doMergeAMT()
async
function
doAllCplusCidsToAMT
Chunked
()
{
async
function
doAllCplusCidsToAMT
()
{
const
cplusCID
=
CID
.
parse
(
'
bafyreie74jtf23zzz2tdgsz7axfrm4pidje43ypqn25v4gkdtfjbcj62km
'
)
// cesium plus import
const
cplusCID
=
CID
.
parse
(
'
bafyreie74jtf23zzz2tdgsz7axfrm4pidje43ypqn25v4gkdtfjbcj62km
'
)
// cesium plus import
const
rootNodeCid
=
CID
.
parse
(
'
bafyreicvlp2p65agkxpzcboedba7zit55us4zvtyyq2wesvsdedy6irwfy
'
)
// empty root cid
const
rootNodeCid
=
CID
.
parse
(
'
bafyreicvlp2p65agkxpzcboedba7zit55us4zvtyyq2wesvsdedy6irwfy
'
)
// empty root cid
allCplusCidsToAMTChunked
(
cplusCID
,
rootNodeCid
)
cplusIndexRequestsToAMT
(
cplusCID
,
rootNodeCid
)
}
}
doAllCplusCidsToAMT
Chunked
()
doAllCplusCidsToAMT
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment