mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
fix: duplicate colors and indices
This commit is contained in:
@@ -16,7 +16,7 @@ export default class IndexedCollection {
|
||||
async addItem(item) {
|
||||
if (!item.id) throw new Error("The item must contain the id field.");
|
||||
|
||||
const exists = await this.exists(item.id);
|
||||
const exists = this.exists(item.id);
|
||||
if (!exists) item.dateCreated = item.dateCreated || Date.now();
|
||||
await this.updateItem(item);
|
||||
if (!exists) {
|
||||
|
||||
@@ -11,20 +11,22 @@ export default class Indexer extends Storage {
|
||||
this.indices = (await this.read(this.type, true)) || [];
|
||||
}
|
||||
|
||||
async exists(key) {
|
||||
exists(key) {
|
||||
return this.indices.includes(key);
|
||||
}
|
||||
|
||||
async index(key) {
|
||||
this.indices[this.indices.length] = key;
|
||||
if (this.exists(key)) return;
|
||||
this.indices.push(key);
|
||||
await this.write(this.type, this.indices);
|
||||
}
|
||||
|
||||
async getIndices() {
|
||||
getIndices() {
|
||||
return this.indices;
|
||||
}
|
||||
|
||||
async deindex(key) {
|
||||
if (!this.exists(key)) return;
|
||||
this.indices.splice(this.indices.indexOf(key), 1);
|
||||
await this.write(this.type, this.indices);
|
||||
}
|
||||
|
||||
@@ -6,15 +6,17 @@ class Migrator {
|
||||
await Promise.all(
|
||||
collections.map(async (collection) => {
|
||||
if (!collection.index || !collection.dbCollection) return;
|
||||
|
||||
await Promise.all(
|
||||
collection.index.map(async (id) => {
|
||||
for (var i = 0; i < collection.index.length; ++i) {
|
||||
let id = collection.index[i];
|
||||
let item = get(id);
|
||||
if (!item) return;
|
||||
|
||||
if (item.deleted && !item.type)
|
||||
return await collection.dbCollection?._collection?.addItem(item);
|
||||
if (!item) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.deleted && !item.type) {
|
||||
await collection.dbCollection?._collection?.addItem(item);
|
||||
continue;
|
||||
}
|
||||
const migrate = migrations[version][item.type || collection.type];
|
||||
if (migrate) item = migrate(item);
|
||||
|
||||
@@ -23,8 +25,7 @@ class Migrator {
|
||||
} else {
|
||||
await collection.dbCollection.add(item);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
})
|
||||
);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user