this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Complete transition from mem to moize

+29 -117
-73
package-lock.json
··· 22 22 "just-debounce-it": "~3.2.0", 23 23 "lz-string": "~1.5.0", 24 24 "masto": "~6.3.1", 25 - "mem": "~9.0.2", 26 25 "moize": "~6.1.6", 27 26 "p-retry": "~6.1.0", 28 27 "p-throttle": "~5.1.0", ··· 5274 5273 "sourcemap-codec": "^1.4.8" 5275 5274 } 5276 5275 }, 5277 - "node_modules/map-age-cleaner": { 5278 - "version": "0.1.3", 5279 - "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz", 5280 - "integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==", 5281 - "dependencies": { 5282 - "p-defer": "^1.0.0" 5283 - }, 5284 - "engines": { 5285 - "node": ">=6" 5286 - } 5287 - }, 5288 5276 "node_modules/masto": { 5289 5277 "version": "6.3.1", 5290 5278 "resolved": "https://registry.npmjs.org/masto/-/masto-6.3.1.tgz", ··· 5295 5283 "isomorphic-ws": "^5.0.0", 5296 5284 "ts-custom-error": "^3.3.1", 5297 5285 "ws": "^8.13.0" 5298 - } 5299 - }, 5300 - "node_modules/mem": { 5301 - "version": "9.0.2", 5302 - "resolved": "https://registry.npmjs.org/mem/-/mem-9.0.2.tgz", 5303 - "integrity": "sha512-F2t4YIv9XQUBHt6AOJ0y7lSmP1+cY7Fm1DRh9GClTGzKST7UWLMx6ly9WZdLH/G/ppM5RL4MlQfRT71ri9t19A==", 5304 - "dependencies": { 5305 - "map-age-cleaner": "^0.1.3", 5306 - "mimic-fn": "^4.0.0" 5307 - }, 5308 - "engines": { 5309 - "node": ">=12.20" 5310 - }, 5311 - "funding": { 5312 - "url": "https://github.com/sindresorhus/mem?sponsor=1" 5313 5286 } 5314 5287 }, 5315 5288 "node_modules/merge-stream": { ··· 5364 5337 }, 5365 5338 "engines": { 5366 5339 "node": ">= 0.6" 5367 - } 5368 - }, 5369 - "node_modules/mimic-fn": { 5370 - "version": "4.0.0", 5371 - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", 5372 - "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==", 5373 - "engines": { 5374 - "node": ">=12" 5375 - }, 5376 - "funding": { 5377 - "url": "https://github.com/sponsors/sindresorhus" 5378 5340 } 5379 5341 }, 5380 5342 "node_modules/minimatch": { ··· 5497 5459 "dev": true, 5498 5460 "dependencies": { 5499 5461 "wrappy": "1" 5500 - } 5501 - }, 5502 - "node_modules/p-defer": { 5503 - "version": "1.0.0", 5504 - "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", 5505 - "integrity": "sha512-wB3wfAxZpk2AzOfUMJNL+d36xothRSyj8EXOa4f6GMqYDN9BJaaSISbsk+wS9abmnebVw95C2Kb5t85UmpCxuw==", 5506 - "engines": { 5507 - "node": ">=4" 5508 5462 } 5509 5463 }, 5510 5464 "node_modules/p-retry": { ··· 11265 11219 "sourcemap-codec": "^1.4.8" 11266 11220 } 11267 11221 }, 11268 - "map-age-cleaner": { 11269 - "version": "0.1.3", 11270 - "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz", 11271 - "integrity": "sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==", 11272 - "requires": { 11273 - "p-defer": "^1.0.0" 11274 - } 11275 - }, 11276 11222 "masto": { 11277 11223 "version": "6.3.1", 11278 11224 "resolved": "https://registry.npmjs.org/masto/-/masto-6.3.1.tgz", ··· 11283 11229 "isomorphic-ws": "^5.0.0", 11284 11230 "ts-custom-error": "^3.3.1", 11285 11231 "ws": "^8.13.0" 11286 - } 11287 - }, 11288 - "mem": { 11289 - "version": "9.0.2", 11290 - "resolved": "https://registry.npmjs.org/mem/-/mem-9.0.2.tgz", 11291 - "integrity": "sha512-F2t4YIv9XQUBHt6AOJ0y7lSmP1+cY7Fm1DRh9GClTGzKST7UWLMx6ly9WZdLH/G/ppM5RL4MlQfRT71ri9t19A==", 11292 - "requires": { 11293 - "map-age-cleaner": "^0.1.3", 11294 - "mimic-fn": "^4.0.0" 11295 11232 } 11296 11233 }, 11297 11234 "merge-stream": { ··· 11335 11272 "requires": { 11336 11273 "mime-db": "1.52.0" 11337 11274 } 11338 - }, 11339 - "mimic-fn": { 11340 - "version": "4.0.0", 11341 - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-4.0.0.tgz", 11342 - "integrity": "sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==" 11343 11275 }, 11344 11276 "minimatch": { 11345 11277 "version": "3.1.2", ··· 11429 11361 "requires": { 11430 11362 "wrappy": "1" 11431 11363 } 11432 - }, 11433 - "p-defer": { 11434 - "version": "1.0.0", 11435 - "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", 11436 - "integrity": "sha512-wB3wfAxZpk2AzOfUMJNL+d36xothRSyj8EXOa4f6GMqYDN9BJaaSISbsk+wS9abmnebVw95C2Kb5t85UmpCxuw==" 11437 11364 }, 11438 11365 "p-retry": { 11439 11366 "version": "6.1.0",
-1
package.json
··· 24 24 "just-debounce-it": "~3.2.0", 25 25 "lz-string": "~1.5.0", 26 26 "masto": "~6.3.1", 27 - "mem": "~9.0.2", 28 27 "moize": "~6.1.6", 29 28 "p-retry": "~6.1.0", 30 29 "p-throttle": "~5.1.0",
+3 -3
src/components/account-info.jsx
··· 1 1 import './account-info.css'; 2 2 3 3 import { Menu, MenuDivider, MenuItem, SubMenu } from '@szhsin/react-menu'; 4 - import mem from 'mem'; 5 4 import { 6 5 useCallback, 7 6 useEffect, ··· 16 15 import getHTMLText from '../utils/getHTMLText'; 17 16 import handleContentLinks from '../utils/handle-content-links'; 18 17 import niceDateTime from '../utils/nice-date-time'; 18 + import pmem from '../utils/pmem'; 19 19 import shortenNumber from '../utils/shorten-number'; 20 20 import showToast from '../utils/show-toast'; 21 21 import states, { hideAllModals } from '../utils/states'; ··· 63 63 id: [currentID], 64 64 }); 65 65 } 66 - const memFetchFamiliarFollowers = mem(fetchFamiliarFollowers, { 66 + const memFetchFamiliarFollowers = pmem(fetchFamiliarFollowers, { 67 67 maxAge: ACCOUNT_INFO_MAX_AGE, 68 68 }); 69 69 ··· 112 112 console.log('posting stats', stats); 113 113 return stats; 114 114 } 115 - const memFetchPostingStats = mem(fetchPostingStats, { 115 + const memFetchPostingStats = pmem(fetchPostingStats, { 116 116 maxAge: ACCOUNT_INFO_MAX_AGE, 117 117 }); 118 118
+1 -1
src/components/media.jsx
··· 1 1 import { getBlurHashAverageColor } from 'fast-blurhash'; 2 - import mem from 'mem'; 3 2 import { Fragment } from 'preact'; 4 3 import { 5 4 useCallback, ··· 10 9 } from 'preact/hooks'; 11 10 import QuickPinchZoom, { make3dTransformValue } from 'react-quick-pinch-zoom'; 12 11 12 + import mem from '../utils/mem'; 13 13 import states from '../utils/states'; 14 14 15 15 import Icon from './icon';
+9 -19
src/components/shortcuts-settings.jsx
··· 4 4 compressToEncodedURIComponent, 5 5 decompressFromEncodedURIComponent, 6 6 } from 'lz-string'; 7 - import mem from 'mem'; 8 7 import { useEffect, useMemo, useRef, useState } from 'preact/hooks'; 9 8 import { useSnapshot } from 'valtio'; 10 9 ··· 13 12 import tabMenuBarUrl from '../assets/tab-menu-bar.svg'; 14 13 15 14 import { api } from '../utils/api'; 15 + import pmem from '../utils/pmem'; 16 16 import showToast from '../utils/show-toast'; 17 17 import states from '../utils/states'; 18 18 ··· 133 133 }, 134 134 list: { 135 135 id: 'list', 136 - title: mem( 137 - async ({ id }) => { 138 - const list = await api().masto.v1.lists.$select(id).fetch(); 139 - return list.title; 140 - }, 141 - { 142 - cacheKey: ([{ id }]) => id, 143 - }, 144 - ), 136 + title: pmem(async ({ id }) => { 137 + const list = await api().masto.v1.lists.$select(id).fetch(); 138 + return list.title; 139 + }), 145 140 path: ({ id }) => `/l/${id}`, 146 141 icon: 'list', 147 142 }, ··· 167 162 }, 168 163 'account-statuses': { 169 164 id: 'account-statuses', 170 - title: mem( 171 - async ({ id }) => { 172 - const account = await api().masto.v1.accounts.$select(id).fetch(); 173 - return account.username || account.acct || account.displayName; 174 - }, 175 - { 176 - cacheKey: ([{ id }]) => id, 177 - }, 178 - ), 165 + title: pmem(async ({ id }) => { 166 + const account = await api().masto.v1.accounts.$select(id).fetch(); 167 + return account.username || account.acct || account.displayName; 168 + }), 179 169 path: ({ id }) => `/a/${id}`, 180 170 icon: 'user', 181 171 },
+4 -12
src/components/status.jsx
··· 9 9 MenuItem, 10 10 } from '@szhsin/react-menu'; 11 11 import { decodeBlurHash } from 'fast-blurhash'; 12 - import mem from 'mem'; 13 12 import pThrottle from 'p-throttle'; 14 13 import { memo } from 'preact/compat'; 15 14 import { ··· 42 41 import isMastodonLinkMaybe from '../utils/isMastodonLinkMaybe'; 43 42 import localeMatch from '../utils/locale-match'; 44 43 import niceDateTime from '../utils/nice-date-time'; 44 + import pmem from '../utils/pmem'; 45 45 import safeBoundingBoxPadding from '../utils/safe-bounding-box-padding'; 46 46 import shortenNumber from '../utils/shorten-number'; 47 47 import showToast from '../utils/show-toast'; ··· 67 67 }); 68 68 69 69 function fetchAccount(id, masto) { 70 - try { 71 - return masto.v1.accounts.$select(id).fetch(); 72 - } catch (e) { 73 - return Promise.reject(e); 74 - } 70 + return masto.v1.accounts.$select(id).fetch(); 75 71 } 76 - const memFetchAccount = mem(fetchAccount); 72 + const memFetchAccount = pmem(fetchAccount); 77 73 78 74 const visibilityText = { 79 75 public: 'Public', ··· 2133 2129 ); 2134 2130 } 2135 2131 2136 - const unfurlMastodonLink = throttle( 2137 - mem(_unfurlMastodonLink, { 2138 - cacheKey: (instance, url) => `${instance}:${url}`, 2139 - }), 2140 - ); 2132 + const unfurlMastodonLink = throttle(pmem(_unfurlMastodonLink)); 2141 2133 2142 2134 function FilteredStatus({ status, filterInfo, instance, containerProps = {} }) { 2143 2135 const {
+3 -4
src/utils/locale-match.jsx
··· 1 1 import { match } from '@formatjs/intl-localematcher'; 2 - import mem from 'mem'; 2 + 3 + import mem from './mem'; 3 4 4 5 function _localeMatch(...args) { 5 6 // Wrap in try/catch because localeMatcher throws on invalid locales ··· 10 11 return defaultLocale || false; 11 12 } 12 13 } 13 - const localeMatch = mem(_localeMatch, { 14 - cacheKey: (args) => args.join(), 15 - }); 14 + const localeMatch = mem(_localeMatch); 16 15 17 16 export default localeMatch;
+5
src/utils/mem.js
··· 1 + import moize from 'moize'; 2 + 3 + export default function mem(fn, opts = {}) { 4 + return moize(fn, { ...opts, maxSize: 100 }); 5 + }
+2 -2
src/utils/pmem.js
··· 1 - import moize from 'moize'; 1 + import mem from './mem'; 2 2 3 3 export default function pmem(fn, opts = {}) { 4 - return moize(fn, { isPromise: true, ...opts, maxSize: Infinity }); 4 + return mem(fn, { isPromise: true, ...opts }); 5 5 }
+2 -2
src/utils/states.js
··· 1 - import mem from 'mem'; 2 1 import { proxy, subscribe } from 'valtio'; 3 2 import { subscribeKey } from 'valtio/utils'; 4 3 5 4 import { api } from './api'; 5 + import pmem from './pmem'; 6 6 import store from './store'; 7 7 8 8 const states = proxy({ ··· 229 229 }); 230 230 } 231 231 232 - const fetchStatus = mem((statusID, masto) => { 232 + const fetchStatus = pmem((statusID, masto) => { 233 233 return masto.v1.statuses.$select(statusID).fetch(); 234 234 });