Skip to content

Commit 9dfa82f

Browse files
committed
Progress report.
1 parent 9d9190d commit 9dfa82f

File tree

3 files changed

+47
-12
lines changed

3 files changed

+47
-12
lines changed

package-lock.json

+34-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
"@tsconfig/node16": "^1.0.3",
1616
"@tsconfig/node16-strictest-esm": "^1.0.3",
1717
"@types/node": "^16",
18+
"@types/progress": "^2.0.5",
1819
"prettier": "2.8.4",
1920
"ts-node": "^10.9.1",
2021
"typescript": "^4.9.5"
2122
},
2223
"dependencies": {
2324
"elastic-builder": "^2.17.3",
24-
"multiformats": "^11"
25+
"multiformats": "^11",
26+
"progress": "^2.0.3"
2527
}
2628
}

src/main.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { default as crypto } from "crypto";
33

44
import { Client } from "@opensearch-project/opensearch";
55
import { default as esb } from "elastic-builder";
6+
import { default as ProgressBar } from "progress";
67

78
const scrollTime = "1m";
89
const srcIndex = "ipfs_files";
@@ -44,17 +45,23 @@ async function* getHits(client: Client, year: number, month: number) {
4445
scroll: scrollTime,
4546
});
4647

47-
var first = true;
48+
var bar: ProgressBar | null = null;
4849
for await (const result of search) {
49-
if (first) {
50+
if (!bar) {
5051
console.info(
5152
`Query returned ${result.body["hits"].total.value} results.`
5253
);
53-
first = false;
54+
bar = new ProgressBar(
55+
"(:rate/s) [:bar] :percent (:current/:total) ETA: :etas Elapsed: :elapsedss",
56+
{
57+
total: result.body["hits"].total.value,
58+
}
59+
);
5460
}
5561

5662
for (const hit of result.body["hits"].hits) {
5763
yield hit;
64+
bar.tick();
5865
}
5966
}
6067
}
@@ -88,8 +95,6 @@ function getSeen(doc: any): string | null {
8895
}
8996

9097
async function* getLinks(documents: AsyncIterable<any>) {
91-
var docCnt = 0;
92-
9398
for await (const doc of documents) {
9499
const to = homogeniseCID(doc._id);
95100
const seen = getSeen(doc);
@@ -102,11 +107,6 @@ async function* getLinks(documents: AsyncIterable<any>) {
102107
seen: seen,
103108
};
104109
}
105-
106-
docCnt++;
107-
if (docCnt % 1000 === 0) {
108-
console.log(`${docCnt} documents processed`);
109-
}
110110
}
111111
}
112112

0 commit comments

Comments
 (0)