あるデータベースから約15,000行を読み取り、データをフォーマットして別のデータベースに書き込む次の関数があります。現在、実行に約 6 秒かかります。JavaScriptを使用してデータをフォーマットせずに、sqliteクエリを使用するだけでこれを行う方法はありますか? またはそれを高速化する別の方法はありますか?
ありがとう
var events = db.open(events.sqlite3);
function updateTimetable() {
var rows = users.execute("SELECT id, complete, strftime('%s000',time) AS realTime, strftime('%H:%M',time) AS Time FROM exerciseLists WHERE patientId = ? ORDER BY time ASC", Alloy.Globals.currentUser);
events.execute("DELETE FROM Events");
events.execute('BEGIN');
while (rows.isValidRow()) {
var colorType;
var active;
var time = rows.fieldByName('Time');
var realTime = rows.fieldByName('realTime');
var now = new Date().getTime();
if (realTime < now) {
colorType = 'red';
active = 'no';
} else {
colorType = 'blue';
active = 'no';
};
if (rows.fieldByName('complete')) {
colorType = 'yellow';
}
if (Alloy.Globals.sessionButton.button.sessionId === rows.fieldByName('id')) {
colorType = 'green';
active = 'yes';
}
function pad(n) {
return n < 10 ? '0' + n : n
}
var d = new Date(parseInt(realTime));
var dYear = d.getFullYear();
var dDay = pad(d.getDate());
var dMonth = pad(d.getMonth()+1);
var dHour = pad(d.getHours()+1);
var dMinute = pad(d.getMinutes()+1);
var dFinal = dYear + "-" + dMonth + "-" + dDay + " " + dHour + ":" + dMinute;
events.execute("INSERT INTO Events (title, date_start, date_end, note, location, identifier, type, attendees, organizer) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", time, dFinal, '(null)', rows.fieldByName('id').toString(), colorType, rows.fieldByName('id').toString(), active, '(null)', '(null)');
rows.next();
}
rows.close();
events.execute('COMMIT');
Alloy.Globals.refreshTimetable();
};