Skip to content

Commit

Permalink
Store hashes as string array instead of bigint set #7
Browse files Browse the repository at this point in the history
bigints and sets are not supported when saving data.
  • Loading branch information
Zachatoo committed Dec 8, 2022
1 parent 2495dd0 commit f42317d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct File {
}

#[wasm_bindgen]
pub fn calculate_file_hash(path: String, data: String, m_time: u32, c_time: u32) -> u64 {
pub fn calculate_file_hash(path: String, data: String, m_time: u32, c_time: u32) -> String {
let file: File = File {
path: path,
data: data,
Expand All @@ -25,7 +25,7 @@ pub fn calculate_file_hash(path: String, data: String, m_time: u32, c_time: u32)
m_time: m_time,
},
};
return calculate_hash(&file);
return calculate_hash(&file).to_string();
}

pub fn calculate_hash<T: Hash>(t: &T) -> u64 {
Expand Down
10 changes: 5 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import initWasm, { calculate_file_hash } from "../pkg/obsidian_achievements.js";
export default class AchievementsPlugin extends Plugin {
settings: Settings;
internalCounts: InternalCounts;
private processedFiles: Set<string>;

async onload() {
console.log("loading Achievements plugin");
Expand Down Expand Up @@ -85,12 +86,11 @@ export default class AchievementsPlugin extends Plugin {
DEFAULT_SETTINGS,
await this.loadData()
);
if (!(this.settings.processedFiles instanceof Set)) {
this.settings.processedFiles = new Set();
}
this.processedFiles = new Set(Array.from(this.settings.processedFiles));
}

async saveSettings() {
this.settings.processedFiles = Array.from(this.processedFiles);
await this.saveData(this.settings);
store.plugin.set(this);
}
Expand Down Expand Up @@ -140,7 +140,7 @@ export default class AchievementsPlugin extends Plugin {
async handleFileChanged(file: TFile, data: string, cache?: CachedMetadata) {
const { mtime, ctime } = file.stat;
const hash = calculate_file_hash(file.path, data, mtime, ctime);
if (this.settings.processedFiles.has(hash)) {
if (this.processedFiles.has(hash)) {
return;
}

Expand Down Expand Up @@ -181,7 +181,7 @@ export default class AchievementsPlugin extends Plugin {
}
}

this.settings.processedFiles.add(hash);
this.processedFiles.add(hash);

await this.saveSettings();
}
Expand Down
4 changes: 2 additions & 2 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface Settings {
achievedAchievementIDs: string[];
processedFiles: Set<bigint>;
processedFiles: string[];
notesCreated: number;
notesDeleted: number;
internalLinksCreated: number;
Expand All @@ -13,7 +13,7 @@ export interface Settings {

export const DEFAULT_SETTINGS: Settings = {
achievedAchievementIDs: [],
processedFiles: new Set(),
processedFiles: [],
notesCreated: 0,
notesDeleted: 0,
internalLinksCreated: 0,
Expand Down

0 comments on commit f42317d

Please sign in to comment.