tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
28
pulls
pipelines
cache homepage tokens to prevent unnessecary renders
awarm.space
9 months ago
b7394212
67519d4b
+10
-6
2 changed files
expand all
collapse all
unified
split
app
home
LeafletList.tsx
storage.ts
+1
-5
app/home/LeafletList.tsx
···
7
7
import { LeafletPreview } from "./LeafletPreview";
8
8
import { useIdentityData } from "components/IdentityProvider";
9
9
import type { Attribute } from "src/replicache/attributes";
10
10
-
import { getIdentityData } from "actions/getIdentityData";
11
10
import { callRPC } from "app/api/rpc/client";
12
11
import { StaticLeafletDataContext } from "components/PageSWRDataProvider";
13
12
···
20
19
fallbackData: [],
21
20
});
22
21
let { identity } = useIdentityData();
23
23
-
let { data: initialFacts, mutate } = useSWR(
22
22
+
let { data: initialFacts } = useSWR(
24
23
"home-leaflet-data",
25
24
async () => {
26
25
if (identity) {
···
34
33
},
35
34
{ fallbackData: props.initialFacts },
36
35
);
37
37
-
useEffect(() => {
38
38
-
mutate();
39
39
-
}, [localLeaflets.length, mutate]);
40
36
let leaflets: Array<
41
37
PermissionToken & {
42
38
leaflets_in_publications?: Array<{
+9
-1
app/home/storage.ts
···
15
15
docs: [],
16
16
};
17
17
const key = "homepageDocs-v1";
18
18
+
let tokenCache = new Map<string, PermissionToken>();
18
19
export function getHomeDocs() {
19
20
let homepageDocs: HomeDocsStorage = JSON.parse(
20
21
window.localStorage.getItem(key) || JSON.stringify(defaultValue),
21
22
);
22
22
-
return homepageDocs.docs;
23
23
+
return homepageDocs.docs.map((d) => {
24
24
+
let cachedToken = tokenCache.get(d.token.id);
25
25
+
if (!cachedToken) {
26
26
+
cachedToken = d.token;
27
27
+
tokenCache.set(d.token.id, d.token);
28
28
+
}
29
29
+
return { ...d, token: cachedToken };
30
30
+
});
23
31
}
24
32
25
33
export function addDocToHome(doc: PermissionToken) {