From 23aee1d1ece7150a3d2c6a7fae63b95a032deb16 Mon Sep 17 00:00:00 2001 From: saul Date: Tue, 4 Apr 2023 14:05:25 +1200 Subject: [PATCH] Remove p-map package and replace with Promise.all. --- package-lock.json | 15 ++++++++++++--- package.json | 1 - src/oplog/log.js | 6 +++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index ec1c801..81cd11c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,6 @@ "level": "^8.0.0", "lru": "^3.1.0", "multiformats": "^11.0.1", - "p-map": "^5.5.0", "p-queue": "^7.3.4", "timeout-abort-controller": "^3.0.0", "uint8arrays": "^4.0.3" @@ -3445,6 +3444,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-4.0.1.tgz", "integrity": "sha512-0poP0T7el6Vq3rstR8Mn4V/IQrpBLO6POkUSrN7RhyY+GF/InCFShQzsQ39T25gkHhLgSLByyAz+Kjb+c2L98w==", + "dev": true, "dependencies": { "clean-stack": "^4.0.0", "indent-string": "^5.0.0" @@ -4322,6 +4322,7 @@ "version": "4.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-4.2.0.tgz", "integrity": "sha512-LYv6XPxoyODi36Dp976riBtSY27VmFo+MKqEU9QCCWyTrdEPDog+RWA7xQWHi6Vbp61j5c4cdzzX1NidnwtUWg==", + "dev": true, "dependencies": { "escape-string-regexp": "5.0.0" }, @@ -4336,6 +4337,7 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz", "integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==", + "dev": true, "engines": { "node": ">=12" }, @@ -6878,6 +6880,7 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-5.0.0.tgz", "integrity": "sha512-m6FAo/spmsW2Ab2fU35JTYwtOKa2yAwXSwgjSv1TJzh4Mh7mC3lzAOVLBprb72XsTrgkEIsl7YrFNAiDiRhIGg==", + "dev": true, "engines": { "node": ">=12" }, @@ -10917,6 +10920,7 @@ "version": "5.5.0", "resolved": "https://registry.npmjs.org/p-map/-/p-map-5.5.0.tgz", "integrity": "sha512-VFqfGDHlx87K66yZrNdI4YGtD70IRyd+zSvgks6mzHPRNkoKy+9EKP4SFC77/vTTQYmRmti7dvqC+m5jBrBAcg==", + "dev": true, "dependencies": { "aggregate-error": "^4.0.0" }, @@ -17320,6 +17324,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-4.0.1.tgz", "integrity": "sha512-0poP0T7el6Vq3rstR8Mn4V/IQrpBLO6POkUSrN7RhyY+GF/InCFShQzsQ39T25gkHhLgSLByyAz+Kjb+c2L98w==", + "dev": true, "requires": { "clean-stack": "^4.0.0", "indent-string": "^5.0.0" @@ -17935,6 +17940,7 @@ "version": "4.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-4.2.0.tgz", "integrity": "sha512-LYv6XPxoyODi36Dp976riBtSY27VmFo+MKqEU9QCCWyTrdEPDog+RWA7xQWHi6Vbp61j5c4cdzzX1NidnwtUWg==", + "dev": true, "requires": { "escape-string-regexp": "5.0.0" }, @@ -17942,7 +17948,8 @@ "escape-string-regexp": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz", - "integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==" + "integrity": "sha512-/veY75JbMK4j1yjvuUxuVsiS/hr/4iHs9FTT6cgTexxdE0Ly/glccBAkloH/DofkjRbZU3bnoj38mOmhkZ0lHw==", + "dev": true } } }, @@ -19788,7 +19795,8 @@ "indent-string": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-5.0.0.tgz", - "integrity": "sha512-m6FAo/spmsW2Ab2fU35JTYwtOKa2yAwXSwgjSv1TJzh4Mh7mC3lzAOVLBprb72XsTrgkEIsl7YrFNAiDiRhIGg==" + "integrity": "sha512-m6FAo/spmsW2Ab2fU35JTYwtOKa2yAwXSwgjSv1TJzh4Mh7mC3lzAOVLBprb72XsTrgkEIsl7YrFNAiDiRhIGg==", + "dev": true }, "inflight": { "version": "1.0.6", @@ -22650,6 +22658,7 @@ "version": "5.5.0", "resolved": "https://registry.npmjs.org/p-map/-/p-map-5.5.0.tgz", "integrity": "sha512-VFqfGDHlx87K66yZrNdI4YGtD70IRyd+zSvgks6mzHPRNkoKy+9EKP4SFC77/vTTQYmRmti7dvqC+m5jBrBAcg==", + "dev": true, "requires": { "aggregate-error": "^4.0.0" } diff --git a/package.json b/package.json index 625f75a..d05e8cc 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "level": "^8.0.0", "lru": "^3.1.0", "multiformats": "^11.0.1", - "p-map": "^5.5.0", "p-queue": "^7.3.4", "timeout-abort-controller": "^3.0.0", "uint8arrays": "^4.0.3" diff --git a/src/oplog/log.js b/src/oplog/log.js index d485af8..5f7cc71 100644 --- a/src/oplog/log.js +++ b/src/oplog/log.js @@ -4,7 +4,6 @@ import Clock from './lamport-clock.js' import Heads from './heads.js' import Sorting from './sorting.js' import MemoryStorage from '../storage/memory.js' -import pMap from 'p-map' const { LastWriteWins, NoZeroes } = Sorting @@ -289,14 +288,15 @@ const Log = async (identity, { logId, logHeads, access, entryStorage, headsStora // filter out traversed and fetched hashes toFetch = [...toFetch, ...next, ...refs].filter(notIndexed) // Function to fetch an entry and making sure it's not a duplicate (check the hash indices) - const fetchEntries = async (hash) => { + const fetchEntries = (hash) => { if (!traversed[hash] && !fetched[hash]) { fetched[hash] = true return get(hash) } } // Fetch the next/reference entries - const nexts = await pMap(toFetch, fetchEntries) + const nexts = await Promise.all(toFetch.map(p => Promise.resolve(p).then(fetchEntries))) + // Add the next and refs fields from the fetched entries to the next round toFetch = nexts .filter(e => e != null)