Skip to content

Commit

Permalink
Merge pull request #465 from fastrodev/dev2
Browse files Browse the repository at this point in the history
chore: update map repo
  • Loading branch information
ynwd authored Sep 29, 2024
2 parents 0ec15b3 + 2db0210 commit 4c87222
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions core/map/mod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ Deno.test("Store: update value", async () => {
});

Deno.test("Store: sync with github periodically", async () => {
await new Promise((resolve) => setTimeout(resolve, 10000));
const g = await store.get("key1");
assertEquals(g, 2);
});
Expand Down Expand Up @@ -189,8 +188,9 @@ Deno.test("Store: sync exist file", async () => {
branch: "store",
token,
});
await newStore.get("exist");
const intervalId = newStore.sync();
await new Promise((resolve) => setTimeout(resolve, 10000));
await new Promise((resolve) => setTimeout(resolve, 15000));
const r = await newStore.get("exist");
assertEquals(r, true);
clearInterval(intervalId);
Expand Down
23 changes: 12 additions & 11 deletions core/map/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,25 @@ export class Store<K extends string | number | symbol, V> {
* @param interval
* @returns intervalId
*/
sync(interval: number = 5000) {
sync(interval: number = 3000) {
if (this.intervalId) clearInterval(this.intervalId);
this.intervalId = setInterval(() => {
if (!this.options || (this.map.size === 0)) return;
this.saveToGitHub({
this.intervalId = setInterval(async () => {
if (!this.options || (this.map.size === 0)) {
return;
}
this.isCommitting = true;
const r = await this.saveToGitHub({
token: this.options.token,
owner: this.options.owner,
repo: this.options.repo,
path: this.options.path,
branch: this.options.branch,
}).then((r) => {
console.log(JSON.stringify({
sha: r.data.content?.sha,
path: r.data.content?.path,
}));
}).catch((error) => {
throw error;
});
console.log(JSON.stringify({
sha: r.data.content?.sha,
path: r.data.content?.path,
}));
this.isCommitting = false;
}, interval);
return this.intervalId;
}
Expand Down
2 changes: 1 addition & 1 deletion core/server/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ if (root) fetchProps(root);
serverOptions: Record<string, any> = {};
store = new Store<string | number | symbol, any>({
owner: Deno.env.get("GITHUB_OWNER") || "fastrodev",
repo: Deno.env.get("GITHUB_REPO") || "fastro",
repo: Deno.env.get("GITHUB_REPO") || "store",
path: Deno.env.get("GITHUB_PATH") || "modules/store/records.json",
branch: Deno.env.get("GITHUB_BRANCH") || "main",
token: Deno.env.get("GITHUB_TOKEN"),
Expand Down

0 comments on commit 4c87222

Please sign in to comment.