Skip to content

Commit

Permalink
Merge pull request #577 from project-violet/dedup-execlude-tags
Browse files Browse the repository at this point in the history
Refactor 010: Dedup exclude tags serialization
  • Loading branch information
violet-dev authored Oct 29, 2024
2 parents f4df425 + 042ed1d commit 2a4a109
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 24 deletions.
8 changes: 4 additions & 4 deletions violet/lib/component/hentai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class HentaiManager {
}
}
final queryString = HitomiManager.translate2query(
'$wwhat ${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ').trim()}');
'$wwhat ${Settings.includeTags} ${Settings.serializedExcludeTags}');

// if (offset == 0 && seed < 0) _latestSeed = new Random().nextDouble() + 1;
await Logger.info('[Database Query]\nSQL: $queryString');
Expand All @@ -261,7 +261,7 @@ class HentaiManager {

static Future<SearchResult> _dbSearch(String what, [int offset = 0]) async {
final queryString = HitomiManager.translate2query(
'$what ${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ').trim()}');
'$what ${Settings.includeTags} ${Settings.serializedExcludeTags}');

await Logger.info('[Database Query]\nSQL: $queryString');

Expand Down Expand Up @@ -318,7 +318,7 @@ class HentaiManager {

static Future<int> countSearch(String what) async {
final queryString = HitomiManager.translate2query(
'$what ${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ').trim()}');
'$what ${Settings.includeTags} ${Settings.serializedExcludeTags}');

var count = (await (await DataBaseManager.getInstance()).query(queryString
.replaceAll('SELECT * FROM', 'SELECT COUNT(*) AS C FROM')))
Expand Down Expand Up @@ -588,7 +588,7 @@ class HentaiManager {
static Future<List<QueryResult>> searchEHentai(String what,
[int next = 0, bool exh = false]) async {
final search = Uri.encodeComponent(
'${Settings.includeTagNetwork ? '${Settings.includeTags} ' : ''}$what${Settings.excludeTagNetwork ? ' ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ').trim()}' : ''}');
'${Settings.includeTagNetwork ? '${Settings.includeTags} ' : ''}$what${Settings.excludeTagNetwork ? ' ${Settings.serializedExcludeTags}' : ''}');
final url =
'https://e${exh ? 'x' : '-'}hentai.org/?${next == 0 ? '' : 'next=$next&'}f_cats=${Settings.searchCategory}&f_search=$search&advsearch=1&f_sname=on&f_stags=on${Settings.searchExpunged ? '&f_sh=on' : ''}&f_spf=&f_spt=';

Expand Down
8 changes: 2 additions & 6 deletions violet/lib/pages/artist_info/artist_info_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class _ArtistInfoPageState extends State<ArtistInfoPage> {
for (int i = 0; i < similars.length; i++) {
var postfix = similars[i].$1.toLowerCase().replaceAll(' ', '_');
var queryString = HitomiManager.translate2query(
'$prefix:$postfix ${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}');
'$prefix:$postfix ${Settings.includeTags} ${Settings.serializedExcludeTags}');
final qm = QueryManager.queryPagination(queryString);
qm.itemsPerPage = 10;

Expand Down Expand Up @@ -272,12 +272,8 @@ class _ArtistInfoPageState extends State<ArtistInfoPage> {

Future<List<QueryResult>> query() async {
final token = '${widget.type.name}:${widget.name.replaceAll(' ', '_')}';
final excludes = Settings.excludeTags
.where((e) => e.trim() != '')
.map((e) => '-$e')
.join(' ');
final query = HitomiManager.translate2query(
'$token ${Settings.includeTags} $excludes');
'$token ${Settings.includeTags} ${Settings.serializedExcludeTags}');
final qm = await QueryManager.query('$query ORDER BY Id DESC');
return qm.results!;
}
Expand Down
2 changes: 1 addition & 1 deletion violet/lib/pages/artist_info/similar_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SimilarListPage extends StatelessWidget {
var postfix = e.toLowerCase().replaceAll(' ', '_');
if (type.isUploader) postfix = e;
var queryString = HitomiManager.translate2query(
'${type.name}:$postfix ${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}');
'${type.name}:$postfix ${Settings.includeTags} ${Settings.serializedExcludeTags}');
final qm = QueryManager.queryPagination(queryString);
qm.itemsPerPage = 10;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class DataBaseDownloadPageState extends State<DataBaseDownloadPage> {

Future deleteUnused() async {
var sql = HitomiManager.translate2query(
'${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim().isNotEmpty).map((e) => '-$e').join(' ')}')
'${Settings.includeTags} ${Settings.serializedExcludeTags}')
.replaceAll(' AND ExistOnHitomi=1', '');
await (await DataBaseManager.getInstance()).delete('HitomiColumnModel',
'NOT (${sql.substring(sql.indexOf('WHERE') + 6)})', []);
Expand Down
2 changes: 1 addition & 1 deletion violet/lib/pages/hot/hot_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class _HotPageState extends ThemeSwitchableState<HotPage>
}

var queryRaw =
'${HitomiManager.translate2query('${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}')} AND ';
'${HitomiManager.translate2query('${Settings.includeTags} ${Settings.serializedExcludeTags}')} AND ';
queryRaw += '(${value.map((e) => 'Id=${e.$1}').join(' OR ')})';
final query = await QueryManager.query(queryRaw);

Expand Down
2 changes: 1 addition & 1 deletion violet/lib/pages/lab/lab/artist_search/artist_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class _ArtistSearchState extends State<ArtistSearch> {
final postfix = e.toLowerCase().replaceAll(' ', '_');

final queryString = HitomiManager.translate2query(
'${selectedType.name}:$postfix ${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}');
'${selectedType.name}:$postfix ${Settings.includeTags} ${Settings.serializedExcludeTags}');
final qm = QueryManager.queryPagination(queryString);
qm.itemsPerPage = 10;

Expand Down
2 changes: 1 addition & 1 deletion violet/lib/pages/lab/lab/recent_record.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class _LabRecentRecordsState extends State<LabRecentRecords> {
max(latestId, xrecords.reduce((x, y) => x.$1 > y.$1 ? x : y).$1 + 1);

var queryRaw =
'${HitomiManager.translate2query('${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}')} AND ';
'${HitomiManager.translate2query('${Settings.includeTags} ${Settings.serializedExcludeTags}')} AND ';

queryRaw += '(${xrecords.map((e) => 'Id=${e.$2}').join(' OR ')})';
var query = await QueryManager.query(queryRaw);
Expand Down
2 changes: 1 addition & 1 deletion violet/lib/pages/lab/lab/recent_record_u.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class _LabRecentRecordsUState extends State<LabRecentRecordsU> {
max(latestId, xrecords.reduce((x, y) => x.$1 > y.$1 ? x : y).$1 + 1);

var queryRaw =
'${HitomiManager.translate2query('${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}')} AND ';
'${HitomiManager.translate2query('${Settings.includeTags} ${Settings.serializedExcludeTags}')} AND ';

queryRaw += '(${xrecords.map((e) => 'Id=${e.$2}').join(' OR ')})';
var query = await QueryManager.query(queryRaw);
Expand Down
2 changes: 1 addition & 1 deletion violet/lib/pages/lab/lab/recent_user_record.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _LabUserRecentRecordsState extends State<LabUserRecentRecords> {
var xrecords = trecords as List<(int, int, int)>;

var queryRaw =
'${HitomiManager.translate2query('${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}')} AND ';
'${HitomiManager.translate2query('${Settings.includeTags} ${Settings.serializedExcludeTags}')} AND ';

queryRaw += '(${xrecords.map((e) => 'Id=${e.$2}').join(' OR ')})';
var query = await QueryManager.query(queryRaw);
Expand Down
2 changes: 1 addition & 1 deletion violet/lib/pages/lab/lab/statistics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class _StatisticsState extends State<Statistics> {
}));

final queryRaw =
'${HitomiManager.translate2query('${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}')} AND '
'${HitomiManager.translate2query('${Settings.includeTags} ${Settings.serializedExcludeTags}')} AND '
'Id IN (${articles.map((e) => e.articleId()).join(',')})';
final query = await QueryManager.query(queryRaw);

Expand Down
2 changes: 1 addition & 1 deletion violet/lib/pages/lab/lab/top_recent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _LabTopRecentState extends State<LabTopRecent> {
var xrecords = trecords as List<(int, int)>;

var queryRaw =
'${HitomiManager.translate2query('${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}')} AND ';
'${HitomiManager.translate2query('${Settings.includeTags} ${Settings.serializedExcludeTags}')} AND ';

queryRaw += 'Id IN (${xrecords.map((e) => e.$1).join(',')})';
var query = await QueryManager.query(queryRaw);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ArtistListPage extends StatelessWidget {

final postfix = e.trim().toLowerCase().replaceAll(' ', '_');
final queryString = HitomiManager.translate2query(
'${isLast ? '' : 'artist:'}$postfix ${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}');
'${isLast ? '' : 'artist:'}$postfix ${Settings.includeTags} ${Settings.serializedExcludeTags}');

final queryManager = QueryManager.queryPagination(queryString);
queryManager.itemsPerPage = 10;
Expand Down
2 changes: 1 addition & 1 deletion violet/lib/pages/settings/db_rebuild_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class _DBRebuildPagePageState extends State<DBRebuildPage> {

Future indexing() async {
var sql = HitomiManager.translate2query(
'${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}');
'${Settings.includeTags} ${Settings.serializedExcludeTags}');

await (await DataBaseManager.getInstance()).delete('HitomiColumnModel',
'NOT (${sql.substring(sql.indexOf('WHERE') + 6)})', []);
Expand Down
2 changes: 1 addition & 1 deletion violet/lib/pages/settings/tag_rebuild_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class _TagRebuildPageState extends State<TagRebuildPage> {
Future indexing() async {
QueryManager qm;
qm = QueryManager.queryPagination(HitomiManager.translate2query(
'${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}'));
'${Settings.includeTags} ${Settings.serializedExcludeTags}'));
qm.itemsPerPage = 50000;

var tags = <String, int>{};
Expand Down
2 changes: 1 addition & 1 deletion violet/lib/pages/viewer/overlay/viewer_tab_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class __ArtistsArticleTabListState extends State<_ArtistsArticleTabList>
}

final queryString = HitomiManager.translate2query(
'($what) ${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ').trim()}');
'($what) ${Settings.includeTags} ${Settings.serializedExcludeTags}');
var queryResult = (await (await DataBaseManager.getInstance())
.query('$queryString ORDER BY Id DESC LIMIT 500'))
.map((e) => QueryResult(result: e))
Expand Down
6 changes: 6 additions & 0 deletions violet/lib/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ class Settings {
static late String? language; // System Language
static late bool translateTags;

static String get serializedExcludeTags => Settings.excludeTags
.where((e) => e.trim() != '')
.map((e) => '-$e')
.join(' ')
.trim();

// Like this Hitomi.la => e-hentai => exhentai => nhentai
static late List<String> routingRule; // image routing rule
static late List<String> searchRule;
Expand Down
2 changes: 1 addition & 1 deletion violet/lib/version/sync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class SyncManager {

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

Expand Down

0 comments on commit 2a4a109

Please sign in to comment.