MOBILE-2319 db: Use REPLACE in inserts
parent
8dc255ea20
commit
a6ea996778
|
@ -514,7 +514,7 @@ export class AddonCalendarProvider {
|
|||
notificationtime: e.notificationtime || -1
|
||||
};
|
||||
|
||||
return db.insertOrUpdateRecord(this.EVENTS_TABLE, eventRecord, { id: eventRecord.id });
|
||||
return db.insertRecord(this.EVENTS_TABLE, eventRecord);
|
||||
}));
|
||||
});
|
||||
|
||||
|
@ -539,7 +539,7 @@ export class AddonCalendarProvider {
|
|||
|
||||
event.notificationtime = time;
|
||||
|
||||
return site.getDb().insertOrUpdateRecord(this.EVENTS_TABLE, event, { id: event.id }).then(() => {
|
||||
return site.getDb().insertRecord(this.EVENTS_TABLE, event).then(() => {
|
||||
return this.scheduleEventNotification(event, time);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -148,11 +148,7 @@ export class AddonMessagesOfflineProvider {
|
|||
deviceoffline: this.appProvider.isOnline() ? 0 : 1
|
||||
};
|
||||
|
||||
return site.getDb().insertOrUpdateRecord(this.MESSAGES_TABLE, entry, {
|
||||
touserid: toUserId,
|
||||
smallmessage: message,
|
||||
timecreated: entry.timecreated
|
||||
}).then(() => {
|
||||
return site.getDb().insertRecord(this.MESSAGES_TABLE, entry).then(() => {
|
||||
return entry;
|
||||
});
|
||||
});
|
||||
|
@ -173,11 +169,7 @@ export class AddonMessagesOfflineProvider {
|
|||
data = { deviceoffline: value ? 1 : 0 };
|
||||
|
||||
messages.forEach((message) => {
|
||||
promises.push(db.insertOrUpdateRecord(this.MESSAGES_TABLE, data, {
|
||||
touserid: message.touserid,
|
||||
smallmessage: message.smallmessage,
|
||||
timecreated: message.timecreated
|
||||
}));
|
||||
promises.push(db.insertRecord(this.MESSAGES_TABLE, data));
|
||||
});
|
||||
|
||||
return Promise.all(promises);
|
||||
|
|
|
@ -218,13 +218,8 @@ export class AddonNotesOfflineProvider {
|
|||
created: now,
|
||||
lastmodified: now
|
||||
};
|
||||
const conditions = {
|
||||
userid: userId,
|
||||
content: content,
|
||||
created: now
|
||||
};
|
||||
|
||||
return site.getDb().insertOrUpdateRecord(this.NOTES_TABLE, data, conditions).then(() => {
|
||||
return site.getDb().insertRecord(this.NOTES_TABLE, data).then(() => {
|
||||
return data;
|
||||
});
|
||||
});
|
||||
|
|
|
@ -402,7 +402,7 @@ export class AddonPushNotificationsProvider {
|
|||
number: value
|
||||
};
|
||||
|
||||
return this.appDB.insertOrUpdateRecord(this.BADGE_TABLE, entry, {siteid: siteId, addon: addon}).then(() => {
|
||||
return this.appDB.insertRecord(this.BADGE_TABLE, entry).then(() => {
|
||||
return value;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -780,7 +780,7 @@ export class CoreSite {
|
|||
entry.key = preSets.cacheKey;
|
||||
}
|
||||
|
||||
return this.db.insertOrUpdateRecord(this.WS_CACHE_TABLE, entry, { id: id });
|
||||
return this.db.insertRecord(this.WS_CACHE_TABLE, entry);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -625,7 +625,7 @@ export class SQLiteDB {
|
|||
questionMarks = ',?'.repeat(keys.length).substr(1);
|
||||
|
||||
return [
|
||||
`INSERT INTO ${table} (${fields}) VALUES (${questionMarks})`,
|
||||
`INSERT OR REPLACE INTO ${table} (${fields}) VALUES (${questionMarks})`,
|
||||
keys.map((key) => data[key])
|
||||
];
|
||||
}
|
||||
|
@ -644,24 +644,6 @@ export class SQLiteDB {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert or update a record.
|
||||
*
|
||||
* @param {string} table The database table.
|
||||
* @param {object} data An object with the fields to insert/update: fieldname=>fieldvalue.
|
||||
* @param {object} conditions The conditions to check if the record already exists (and to update it).
|
||||
* @return {Promise<any>} Promise resolved with done.
|
||||
*/
|
||||
insertOrUpdateRecord(table: string, data: object, conditions: object): Promise<any> {
|
||||
return this.getRecord(table, conditions).then(() => {
|
||||
// It exists, update it.
|
||||
return this.updateRecords(table, data, conditions);
|
||||
}).catch(() => {
|
||||
// Doesn't exist, insert it.
|
||||
return this.insertRecord(table, data);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a record into a table and return the "rowId" field.
|
||||
*
|
||||
|
|
|
@ -699,7 +699,7 @@ export class CoreCourseProvider {
|
|||
previousDownloadTime: previousDownloadTime
|
||||
};
|
||||
|
||||
return site.getDb().insertOrUpdateRecord(this.COURSE_STATUS_TABLE, data, { id: courseId });
|
||||
return site.getDb().insertRecord(this.COURSE_STATUS_TABLE, data);
|
||||
}
|
||||
}).then(() => {
|
||||
// Success inserting, trigger event.
|
||||
|
|
|
@ -417,7 +417,9 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate {
|
|||
courseId: courseId,
|
||||
time: this.timeUtils.timestamp()
|
||||
};
|
||||
site.getDb().insertOrUpdateRecord(this.CHECK_UPDATES_TIMES_TABLE, entry, { courseId: courseId });
|
||||
site.getDb().insertRecord(this.CHECK_UPDATES_TIMES_TABLE, entry).catch(() => {
|
||||
// Ignore errors.
|
||||
});
|
||||
|
||||
return this.treatCheckUpdatesResult(data.toCheck, response, result);
|
||||
}).catch((error) => {
|
||||
|
|
|
@ -671,7 +671,7 @@ export class LocalNotificationsMock extends LocalNotifications {
|
|||
notification = Object.assign({}, notification); // Clone the object.
|
||||
notification.triggered = !!triggered;
|
||||
|
||||
return this.appDB.insertOrUpdateRecord(this.DESKTOP_NOTIFS_TABLE, notification, { id: notification.id });
|
||||
return this.appDB.insertRecord(this.DESKTOP_NOTIFS_TABLE, notification);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -383,7 +383,7 @@ export class CoreUserProvider {
|
|||
profileimageurl: avatar
|
||||
};
|
||||
|
||||
return site.getDb().insertOrUpdateRecord(this.USERS_TABLE, userRecord, { id: userId });
|
||||
return site.getDb().insertRecord(this.USERS_TABLE, userRecord);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -81,6 +81,6 @@ export class CoreConfigProvider {
|
|||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
set(name: string, value: boolean | number | string): Promise<any> {
|
||||
return this.appDB.insertOrUpdateRecord(this.TABLE_NAME, { name: name, value: value }, { name: name });
|
||||
return this.appDB.insertRecord(this.TABLE_NAME, { name: name, value: value });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -459,7 +459,7 @@ export class CoreCronDelegate {
|
|||
value: time
|
||||
};
|
||||
|
||||
return this.appDB.insertOrUpdateRecord(this.CRON_TABLE, entry, { id: id });
|
||||
return this.appDB.insertRecord(this.CRON_TABLE, entry);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -477,7 +477,7 @@ export class CoreFilepoolProvider {
|
|||
componentId: componentId || ''
|
||||
};
|
||||
|
||||
return db.insertOrUpdateRecord(this.LINKS_TABLE, newEntry, { fileId: fileId });
|
||||
return db.insertRecord(this.LINKS_TABLE, newEntry);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -544,7 +544,7 @@ export class CoreFilepoolProvider {
|
|||
values.fileId = fileId;
|
||||
|
||||
return this.sitesProvider.getSiteDb(siteId).then((db) => {
|
||||
return db.insertOrUpdateRecord(this.FILES_TABLE, values, { fileId: fileId });
|
||||
return db.insertRecord(this.FILES_TABLE, values);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2766,7 +2766,7 @@ export class CoreFilepoolProvider {
|
|||
// The package already has this status, no need to change it.
|
||||
promise = Promise.resolve();
|
||||
} else {
|
||||
promise = site.getDb().insertOrUpdateRecord(this.PACKAGES_TABLE, packageEntry, { id: packageId });
|
||||
promise = site.getDb().insertRecord(this.PACKAGES_TABLE, packageEntry);
|
||||
}
|
||||
|
||||
return promise.then(() => {
|
||||
|
|
|
@ -500,6 +500,6 @@ export class CoreLocalNotificationsProvider {
|
|||
at: parseInt(notification.at, 10)
|
||||
};
|
||||
|
||||
return this.appDB.insertOrUpdateRecord(this.TRIGGERED_TABLE, entry, { id: notification.id });
|
||||
return this.appDB.insertRecord(this.TRIGGERED_TABLE, entry);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -623,7 +623,7 @@ export class CoreSitesProvider {
|
|||
loggedOut: 0
|
||||
};
|
||||
|
||||
return this.appDB.insertOrUpdateRecord(this.SITES_TABLE, entry, { id: id });
|
||||
return this.appDB.insertRecord(this.SITES_TABLE, entry);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -895,7 +895,7 @@ export class CoreSitesProvider {
|
|||
siteId: siteId
|
||||
};
|
||||
|
||||
return this.appDB.insertOrUpdateRecord(this.CURRENT_SITE_TABLE, entry, { id: 1 }).then(() => {
|
||||
return this.appDB.insertRecord(this.CURRENT_SITE_TABLE, entry).then(() => {
|
||||
this.eventsProvider.trigger(CoreEventsProvider.LOGIN, {}, siteId);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ export class CoreSyncProvider {
|
|||
data.component = component;
|
||||
data.id = id;
|
||||
|
||||
return db.insertOrUpdateRecord(this.SYNC_TABLE, data, { component: component, id: id });
|
||||
return db.insertRecord(this.SYNC_TABLE, data);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue