Fix unnecessary link preview fetches.

pull/500/head
Mikunj 6 years ago
parent c48ae80468
commit 0636e635d5

@ -13,6 +13,9 @@
window.Signal = window.Signal || {};
window.Signal.LinkPreviews = window.Signal.LinkPreviews || {};
// A cache mapping url to fetched previews
const previewCache = {};
async function makeChunkedRequest(url) {
const PARALLELISM = 3;
const size = await textsecure.messaging.getProxiedSize(url);
@ -68,7 +71,21 @@
return StringView.arrayBufferToHex(digest);
}
async function getPreview(url) {
// Wrapper function which utilizes cache
async function getPreview(url, skipCache = false) {
// If we have a request cached then use that
if (!skipCache && url in previewCache) {
return previewCache[url];
}
// Start the request
const promise = _getPreview(url);
previewCache[url] = promise;
return promise;
}
async function _getPreview(url) {
let html;
try {
html = await textsecure.messaging.makeProxiedRequest(url);

@ -94,7 +94,11 @@ export class JazzIcon extends React.PureComponent<Props> {
private hueShift(colors: Array<string>, generator: RNG) {
const amount = generator.random() * 30 - wobble / 2;
return colors.map(hex => Color(hex).rotate(amount).hex());
return colors.map(hex =>
Color(hex)
.rotate(amount)
.hex()
);
}
private genShape(

Loading…
Cancel
Save