Skip to content

Commit

Permalink
hitomi: add exists_on_hitomi filtering option to translate2query
Browse files Browse the repository at this point in the history
  • Loading branch information
violet-dev committed Oct 15, 2023
1 parent 8637972 commit ae1668c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 6 additions & 4 deletions lib/component/hitomi/hitomi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,17 @@ class HitomiManager {
return result;
}

static String translate2query(String tokens) {
static String translate2query(String tokens, {bool filter = true}) {
tokens = tokens.trim();
final nn = int.tryParse(tokens.split(' ')[0]);
if (nn != null) {
return 'SELECT * FROM HitomiColumnModel WHERE Id=$nn';
}

final filterExistsOnHitomi = !Settings.searchPure && filter;

if (tokens.isEmpty) {
return 'SELECT * FROM HitomiColumnModel WHERE ${!Settings.searchPure ? 'ExistOnHitomi=1' : ''}';
return 'SELECT * FROM HitomiColumnModel WHERE ${filterExistsOnHitomi ? 'ExistOnHitomi=1' : ''}';
}

final split =
Expand Down Expand Up @@ -412,7 +414,7 @@ class HitomiManager {
prefix = 'Class';
break;
case 'recent':
return 'SELECT * FROM HitomiColumnModel ${!Settings.searchPure ? 'ExistOnHitomi=1' : ''}';
return 'SELECT * FROM HitomiColumnModel ${filterExistsOnHitomi ? 'where ExistOnHitomi=1' : ''}';
}
if (prefix == '') return '';
if (postfix == '') postfix = ss[1].replaceAll('_', ' ');
Expand Down Expand Up @@ -456,6 +458,6 @@ class HitomiManager {
}
}

return 'SELECT * FROM HitomiColumnModel WHERE $where ${!Settings.searchPure ? ' AND ExistOnHitomi=1' : ''}';
return 'SELECT * FROM HitomiColumnModel WHERE $where ${filterExistsOnHitomi ? ' AND ExistOnHitomi=1' : ''}';
}
}
7 changes: 4 additions & 3 deletions lib/version/sync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,10 @@ class SyncManager {
}

if (Settings.useOptimizeDatabase && filteredIter.isNotEmpty) {
var sql = HitomiManager.translate2query(
'${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}')
.replaceAll(' AND ExistOnHitomi=1', '');
final sql = HitomiManager.translate2query(
'${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}',
filter: false,
);

await (await DataBaseManager.getInstance()).delete('HitomiColumnModel',
'NOT (${sql.substring(sql.indexOf('WHERE') + 6)})', []);
Expand Down

0 comments on commit ae1668c

Please sign in to comment.