Skip to content

Commit dc8b91f

Browse files
committed
Do not use cache while updating schema
1 parent 85f0109 commit dc8b91f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

options/index.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,13 @@ function OptionsPage() {
218218
return schemaList.schemas.filter(x => x.id == imeSettings.schema)[0] || null;
219219
}
220220

221-
async function downloadSchema(id: string) {
221+
async function downloadSchema(id: string, update: boolean = false) {
222222
try {
223+
const fetchInit: RequestInit = { cache: "no-cache" };
223224
setDownloadSchemaId(id);
224225
setDownloadProgress(0);
225226
const schemaFile = `build/${id}.schema.yaml`;
226-
const schemaYaml: string = await fetch(`${kRepoUrl}/${schemaFile}`).then(x => x.text());
227+
const schemaYaml: string = await fetch(`${kRepoUrl}/${schemaFile}`, fetchInit).then(x => x.text());
227228
const schema = parse(schemaYaml);
228229

229230
const dependencies: Set<string> = new Set();
@@ -239,7 +240,7 @@ function OptionsPage() {
239240
const opencc = schema[tn[1] ?? "simplifier"];
240241
const configPath = `shared/opencc/${opencc?.opencc_config ?? "t2s.json"}`;
241242
dependencies.add(configPath);
242-
const opencc_config = await fetch(`${kRepoUrl}/${configPath}`).then(x => x.text());
243+
const opencc_config = await fetch(`${kRepoUrl}/${configPath}`, fetchInit).then(x => x.text());
243244
const config = JSON.parse(opencc_config);
244245

245246
function parseDict(dict) {
@@ -296,12 +297,12 @@ function OptionsPage() {
296297
const fs = await getFs();
297298
// Phase 1: Download small files and get size of big files
298299
for (const f of dependencies) {
299-
if (await fs.readEntry(`/root/${f}`)) {
300+
if (await fs.readEntry(`/root/${f}`) && !update) {
300301
// file already exists
301302
console.log(`${f} already exists, skipped`);
302303
} else {
303304
let controller = new AbortController();
304-
const res = await fetch(`${kRepoUrl}/${f}`, { signal: controller.signal });
305+
const res = await fetch(`${kRepoUrl}/${f}`, { signal: controller.signal }, fetchInit);
305306
const size = parseInt(res.headers.get('Content-Length'));
306307
if ((size && size < 70 * 1024) ||
307308
// If response is gzipped, size = NaN
@@ -327,7 +328,7 @@ function OptionsPage() {
327328
let phase2TotalSize = _.sum(phase2Sizes);
328329
for (let i = 0; i < phase2Files.length; i++) {
329330
const f = phase2Files[i];
330-
const res = await fetch(`${kRepoUrl}/${f}`);
331+
const res = await fetch(`${kRepoUrl}/${f}`, fetchInit);
331332
const reader = res.body.getReader();
332333
const buf = new ArrayBuffer(phase2Sizes[i]);
333334
let offset = 0;
@@ -420,7 +421,7 @@ function OptionsPage() {
420421
primary={<>{schema.name}
421422
{localSchemaList.includes(schema.id) &&
422423
<Link component="button" underline="hover"
423-
onClick={() => downloadSchema(schema.id)}
424+
onClick={() => downloadSchema(schema.id, true)}
424425
style={{ marginLeft: "8px" }}
425426
disabled={downloadSchemaId != null}>
426427
{$$("update_schema")}

0 commit comments

Comments
 (0)