perf(web): optimize adding/removing tags to files

This commit is contained in:
Masahiko AMANO 2023-02-17 13:29:57 +03:00
parent 832eb72bf4
commit 3f5527db56

View File

@ -266,23 +266,31 @@ $(document).on("submit", "#menu-file-view form", function (e) {
alert("Something went wrong!"); alert("Something went wrong!");
return; return;
} }
let toadd = "", toremove = "";
resp.data.forEach(tanzaku => { resp.data.forEach(tanzaku => {
let current = $(`.list-item[tid="${tanzaku.id}"]`); let current = $(`.list-item[tid="${tanzaku.id}"]`);
if (!current.hasClass("selected") && if (!current.hasClass("selected")) {
!tdb_query(db_name, 9, '' + current_sasa.id + ' ' + tanzaku.id).status) { toremove += ' ' + tanzaku.id;
console.log("ERROR: failed to remove kazari: " + current_sasa.id + '-' + tanzaku.id);
} }
}); });
$(".list-item.tanzaku.selected").each(function (index, element) { $(".list-item.tanzaku.selected").each(function (index, element) {
let tid = parseInt($(element).attr("tid")); let tid = parseInt($(element).attr("tid"));
if (resp.data.find(t => t.id === tid) != null) { if (resp.data.find(t => t.id === tid) == null) {
return; toadd += ' ' + tid;
}
if (!tdb_query(db_name, 10, '' + current_sasa.id + ' ' + tid)) {
console.log("ERROR: failed to add kazari: " + current_sasa.id + '-' + tid);
} }
}); });
alert("Saved changes!"); let status = true;
if (toadd !== "" && !tdb_query(db_name, 26, '' + current_sasa.id + toadd).status) {
status = false;
}
if (toremove !== "" && !tdb_query(db_name, 25, '' + current_sasa.id + toremove).status) {
status = false;
}
if (status) {
alert("Saved changes!");
} else {
alert("Something went wrong!");
}
}); });
$(document).on("submit", "#menu-tag-view form", function (e) { $(document).on("submit", "#menu-tag-view form", function (e) {
@ -305,23 +313,31 @@ $(document).on("submit", "#menu-tag-view form", function (e) {
alert("Something went wrong!"); alert("Something went wrong!");
return; return;
} }
let toadd = "", toremove = "";
resp.data.forEach(sasa => { resp.data.forEach(sasa => {
let current = $(`.list-item[sid="${sasa.id}"]`); let current = $(`.list-item[sid="${sasa.id}"]`);
if (!current.hasClass("selected") && if (!current.hasClass("selected")) {
!tdb_query(db_name, 9, '' + sasa.id + ' ' + current_tanzaku.id).status) { toremove += ' ' + sasa.id;
console.log("ERROR: failed to remove kazari: " + sasa.id + '-' + current_tanzaku.id);
} }
}); });
$(".list-item.sasa.selected").each(function (index, element) { $(".list-item.sasa.selected").each(function (index, element) {
let sid = parseInt($(element).attr("sid")); let sid = parseInt($(element).attr("sid"));
if (resp.data.find(s => s.id === sid) != null) { if (resp.data.find(s => s.id === sid) == null) {
return; toadd += ' ' + sid;
}
if (!tdb_query(db_name, 10, '' + sid + ' ' + current_tanzaku.id)) {
console.log("ERROR: failed to add kazari: " + sid + '-' + current_tanzaku.id);
} }
}); });
alert("Saved changes!"); let status = true;
if (toadd !== "" && !tdb_query(db_name, 42, '' + current_tanzaku.id + toadd).status) {
status = false;
}
if (toremove !== "" && !tdb_query(db_name, 41, '' + current_tanzaku.id + toremove).status) {
status = false;
}
if (status) {
alert("Saved changes!");
} else {
alert("Something went wrong!");
}
}); });
$(document).on("click", "#btn-remove", function (e) { $(document).on("click", "#btn-remove", function (e) {