Add unique ID per post and an index to the db for that

This commit is contained in:
“bobbydigitales”
2024-03-24 22:51:33 -07:00
parent b07a93246f
commit 49a2c8b011
4 changed files with 7 additions and 2 deletions

View File

@@ -36,6 +36,7 @@ export function openDatabase(userID:string): Promise<IDBDatabase> {
if (!db.objectStoreNames.contains(storeName)) {
let store = db.createObjectStore(storeName, { keyPath: "id", autoIncrement: true });
store.createIndex("datetimeIndex", "post_timestamp", { unique: false });
store.createIndex("postIDIndex", "data.post_id", { unique: true });
}
};

View File

@@ -16,6 +16,7 @@ declare let marked: any;
class Post {
post_timestamp: Date;
post_id: string;
author: string;
author_id: string;
text: string;
@@ -27,6 +28,7 @@ class Post {
constructor(author: string, author_id: string, text: string, post_timestamp: Date, imageData: ArrayBuffer | null = null, importedFrom: "twitter" | null = null, importSource: any = null) {
this.post_timestamp = post_timestamp;
this.post_id = generateID();
this.author = author;
this.author_id = author_id;