new: change update time when selected

This commit is contained in:
Hiddify
2024-01-31 10:43:53 +01:00
parent 3d3a190014
commit 7639296ca4

View File

@@ -45,6 +45,7 @@ class ProfileDao extends DatabaseAccessor<AppDatabase>
..limit(1)) ..limit(1))
.getSingleOrNull(); .getSingleOrNull();
} }
@override @override
Future<ProfileEntry?> getByName(String name) async { Future<ProfileEntry?> getByName(String name) async {
return (select(profileEntries) return (select(profileEntries)
@@ -76,12 +77,13 @@ class ProfileDao extends DatabaseAccessor<AppDatabase>
}) { }) {
return (profileEntries.select() return (profileEntries.select()
..orderBy( ..orderBy(
[(tbl) => OrderingTerm( [
expression: tbl.active, (tbl) => OrderingTerm(
mode: OrderingMode.desc, expression: tbl.active,
), mode: OrderingMode.desc,
),
(tbl) { (tbl) {
final trafficRatio = (tbl.download + tbl.upload) / tbl.total; final trafficRatio = (tbl.download + tbl.upload) / tbl.total;
final isExpired = final isExpired =
tbl.expire.isSmallerOrEqualValue(DateTime.now()); tbl.expire.isSmallerOrEqualValue(DateTime.now());
return OrderingTerm( return OrderingTerm(
@@ -93,9 +95,8 @@ class ProfileDao extends DatabaseAccessor<AppDatabase>
}, },
switch (sort) { switch (sort) {
ProfilesSort.name => (tbl) => OrderingTerm( ProfilesSort.name => (tbl) => OrderingTerm(
expression: tbl.name, expression: tbl.name,
mode: orderMap[sortMode]!, mode: orderMap[sortMode]!,
), ),
ProfilesSort.lastUpdate => (tbl) => OrderingTerm( ProfilesSort.lastUpdate => (tbl) => OrderingTerm(
expression: tbl.lastUpdate, expression: tbl.lastUpdate,
@@ -124,12 +125,13 @@ class ProfileDao extends DatabaseAccessor<AppDatabase>
Future<void> edit(String id, ProfileEntriesCompanion entry) async { Future<void> edit(String id, ProfileEntriesCompanion entry) async {
await transaction( await transaction(
() async { () async {
if (entry.active.present && entry.active.value) { if (entry.active.present && entry.active.value) {
await update(profileEntries) await update(profileEntries)
.write(const ProfileEntriesCompanion(active: Value(false))); .write(const ProfileEntriesCompanion(active: Value(false)));
} }
await (update(profileEntries)..where((tbl) => tbl.id.equals(id))) await (update(profileEntries)..where((tbl) => tbl.id.equals(id)))
.write(entry); .write(entry.copyWith(lastUpdate: Value(DateTime.now())));
}, },
); );
} }