small web feature initial
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/daos/small_web_item_dao.drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/database.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/definitions.drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/models/kagi_small_web_mode.dart';
|
||||
import 'package:weblibre/features/small_web/data/models/small_web_source_kind.dart';
|
||||
|
||||
@DriftAccessor()
|
||||
class SmallWebItemDao extends DatabaseAccessor<SmallWebDatabase>
|
||||
with $SmallWebItemDaoMixin {
|
||||
SmallWebItemDao(super.attachedDatabase);
|
||||
|
||||
SingleOrNullSelectable<DateTime?> getLatestFetchedAt(
|
||||
SmallWebSourceKind sourceKind,
|
||||
KagiSmallWebMode? mode,
|
||||
) {
|
||||
final query = selectOnly(db.smallWebMemberships)
|
||||
..addColumns([db.smallWebMemberships.fetchedAt])
|
||||
..where(
|
||||
db.smallWebMemberships.sourceKind.equalsValue(sourceKind) &
|
||||
(mode == null
|
||||
? db.smallWebMemberships.mode.isNull()
|
||||
: db.smallWebMemberships.mode.equals(mode.name)),
|
||||
)
|
||||
..orderBy([
|
||||
OrderingTerm(
|
||||
expression: db.smallWebMemberships.fetchedAt,
|
||||
mode: OrderingMode.desc,
|
||||
),
|
||||
])
|
||||
..limit(1);
|
||||
|
||||
return query.map((row) => row.read(db.smallWebMemberships.fetchedAt));
|
||||
}
|
||||
|
||||
Selectable<SmallWebItem> getDiscoverableKagiItems(
|
||||
KagiSmallWebMode mode,
|
||||
String? category,
|
||||
) {
|
||||
return db.definitionsDrift.getDiscoverableKagiItems(
|
||||
sourceKind: SmallWebSourceKind.kagi,
|
||||
mode: mode.name,
|
||||
category: category,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> updateTitle(String id, String title) {
|
||||
return (db.smallWebItems.update()..where((i) => i.id.equals(id))).write(
|
||||
SmallWebItemsCompanion(
|
||||
title: Value(title),
|
||||
updatedAt: Value(DateTime.now()),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// dart format width=80
|
||||
// ignore_for_file: type=lint
|
||||
import 'package:drift/drift.dart' as i0;
|
||||
import 'package:weblibre/features/small_web/data/database/database.dart' as i1;
|
||||
|
||||
mixin $SmallWebItemDaoMixin on i0.DatabaseAccessor<i1.SmallWebDatabase> {
|
||||
SmallWebItemDaoManager get managers => SmallWebItemDaoManager(this);
|
||||
}
|
||||
|
||||
class SmallWebItemDaoManager {
|
||||
final $SmallWebItemDaoMixin _db;
|
||||
SmallWebItemDaoManager(this._db);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/daos/small_web_visit_dao.drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/database.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/definitions.drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/models/kagi_small_web_mode.dart';
|
||||
import 'package:weblibre/features/small_web/data/models/small_web_source_kind.dart';
|
||||
|
||||
@DriftAccessor()
|
||||
class SmallWebVisitDao extends DatabaseAccessor<SmallWebDatabase>
|
||||
with $SmallWebVisitDaoMixin {
|
||||
SmallWebVisitDao(super.attachedDatabase);
|
||||
|
||||
Future<void> insertVisit(SmallWebVisit visit) {
|
||||
return db.smallWebVisits.insertOne(visit);
|
||||
}
|
||||
|
||||
Selectable<GetRecentVisitsResult> getRecentVisits({
|
||||
required SmallWebSourceKind sourceKind,
|
||||
required KagiSmallWebMode? mode,
|
||||
int limit = 50,
|
||||
}) {
|
||||
return db.definitionsDrift.getRecentVisits(
|
||||
sourceKind: sourceKind,
|
||||
mode: mode?.name,
|
||||
limit: limit,
|
||||
);
|
||||
}
|
||||
|
||||
Selectable<String> getRecentItemIds({
|
||||
required SmallWebSourceKind sourceKind,
|
||||
required KagiSmallWebMode? mode,
|
||||
int limit = 20,
|
||||
}) {
|
||||
return db.definitionsDrift.getRecentVisitItemIds(
|
||||
sourceKind: sourceKind,
|
||||
mode: mode?.name,
|
||||
limit: limit,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> deleteVisitById(String visitId) {
|
||||
return (db.delete(
|
||||
db.smallWebVisits,
|
||||
)..where((t) => t.id.equals(visitId))).go();
|
||||
}
|
||||
|
||||
Future<void> deleteVisitsBySourceAndMode({
|
||||
required SmallWebSourceKind sourceKind,
|
||||
required KagiSmallWebMode? mode,
|
||||
}) {
|
||||
return (db.delete(db.smallWebVisits)..where(
|
||||
(t) =>
|
||||
t.sourceKind.equalsValue(sourceKind) &
|
||||
(mode == null ? t.mode.isNull() : t.mode.equals(mode.name)),
|
||||
))
|
||||
.go();
|
||||
}
|
||||
|
||||
Future<void> deleteAllVisits() {
|
||||
return db.delete(db.smallWebVisits).go();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// dart format width=80
|
||||
// ignore_for_file: type=lint
|
||||
import 'package:drift/drift.dart' as i0;
|
||||
import 'package:weblibre/features/small_web/data/database/database.dart' as i1;
|
||||
|
||||
mixin $SmallWebVisitDaoMixin on i0.DatabaseAccessor<i1.SmallWebDatabase> {
|
||||
SmallWebVisitDaoManager get managers => SmallWebVisitDaoManager(this);
|
||||
}
|
||||
|
||||
class SmallWebVisitDaoManager {
|
||||
final $SmallWebVisitDaoMixin _db;
|
||||
SmallWebVisitDaoManager(this._db);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/daos/wander_console_dao.drift.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/database.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/definitions.drift.dart';
|
||||
|
||||
@DriftAccessor()
|
||||
class WanderConsoleDao extends DatabaseAccessor<SmallWebDatabase>
|
||||
with $WanderConsoleDaoMixin {
|
||||
WanderConsoleDao(super.attachedDatabase);
|
||||
|
||||
Future<void> upsertConsole(WanderConsole console) {
|
||||
return db.wanderConsoles.insertOne(
|
||||
console,
|
||||
onConflict: DoUpdate(
|
||||
(old) => WanderConsolesCompanion(
|
||||
lastFetchedAt: Value(console.lastFetchedAt),
|
||||
lastFetchFailed: Value(console.lastFetchFailed),
|
||||
),
|
||||
target: [db.wanderConsoles.url],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
SingleOrNullSelectable<WanderConsole?> getConsole(Uri url) {
|
||||
return (db.wanderConsoles.select()..where((c) => c.url.equalsValue(url)));
|
||||
}
|
||||
|
||||
Selectable<Uri> getExistingConsoleUrls(List<Uri> urls) {
|
||||
final query = selectOnly(db.wanderConsoles)
|
||||
..addColumns([db.wanderConsoles.url])
|
||||
..where(db.wanderConsoles.url.isInValues(urls));
|
||||
|
||||
return query.map((row) => row.readWithConverter(db.wanderConsoles.url)!);
|
||||
}
|
||||
|
||||
Selectable<Uri> getDiscoveredConsoleUrls({int limit = 1000}) {
|
||||
return db.definitionsDrift.getDiscoveredConsoleUrls(limit: limit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// dart format width=80
|
||||
// ignore_for_file: type=lint
|
||||
import 'package:drift/drift.dart' as i0;
|
||||
import 'package:weblibre/features/small_web/data/database/database.dart' as i1;
|
||||
|
||||
mixin $WanderConsoleDaoMixin on i0.DatabaseAccessor<i1.SmallWebDatabase> {
|
||||
WanderConsoleDaoManager get managers => WanderConsoleDaoManager(this);
|
||||
}
|
||||
|
||||
class WanderConsoleDaoManager {
|
||||
final $WanderConsoleDaoMixin _db;
|
||||
WanderConsoleDaoManager(this._db);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2024-2026 Fabian Freund.
|
||||
*
|
||||
* This file is part of WebLibre
|
||||
* (see https://weblibre.eu).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift_dev/api/migrations_native.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/daos/small_web_item_dao.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/daos/small_web_visit_dao.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/daos/wander_console_dao.dart';
|
||||
import 'package:weblibre/features/small_web/data/database/database.drift.dart';
|
||||
|
||||
@DriftDatabase(
|
||||
include: {'definitions.drift'},
|
||||
daos: [SmallWebItemDao, SmallWebVisitDao, WanderConsoleDao],
|
||||
)
|
||||
class SmallWebDatabase extends $SmallWebDatabase {
|
||||
SmallWebDatabase(super.e);
|
||||
|
||||
@override
|
||||
int get schemaVersion => 1;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
beforeOpen: (details) async {
|
||||
if (kDebugMode) {
|
||||
await validateDatabaseSchema();
|
||||
}
|
||||
await customStatement('PRAGMA foreign_keys = ON;');
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
// dart format width=80
|
||||
// ignore_for_file: type=lint
|
||||
import 'package:drift/drift.dart' as i0;
|
||||
import 'package:weblibre/features/small_web/data/database/definitions.drift.dart'
|
||||
as i1;
|
||||
import 'package:weblibre/features/small_web/data/database/daos/small_web_item_dao.dart'
|
||||
as i2;
|
||||
import 'package:weblibre/features/small_web/data/database/database.dart' as i3;
|
||||
import 'package:weblibre/features/small_web/data/database/daos/small_web_visit_dao.dart'
|
||||
as i4;
|
||||
import 'package:weblibre/features/small_web/data/database/daos/wander_console_dao.dart'
|
||||
as i5;
|
||||
import 'package:drift/internal/modular.dart' as i6;
|
||||
import 'package:sqlite3/common.dart' as i7;
|
||||
|
||||
abstract class $SmallWebDatabase extends i0.GeneratedDatabase {
|
||||
$SmallWebDatabase(i0.QueryExecutor e) : super(e);
|
||||
$SmallWebDatabaseManager get managers => $SmallWebDatabaseManager(this);
|
||||
late final i1.SmallWebItems smallWebItems = i1.SmallWebItems(this);
|
||||
late final i1.SmallWebMemberships smallWebMemberships =
|
||||
i1.SmallWebMemberships(this);
|
||||
late final i1.WanderConsoles wanderConsoles = i1.WanderConsoles(this);
|
||||
late final i1.WanderConsoleNeighbors wanderConsoleNeighbors =
|
||||
i1.WanderConsoleNeighbors(this);
|
||||
late final i1.SmallWebVisits smallWebVisits = i1.SmallWebVisits(this);
|
||||
late final i2.SmallWebItemDao smallWebItemDao = i2.SmallWebItemDao(
|
||||
this as i3.SmallWebDatabase,
|
||||
);
|
||||
late final i4.SmallWebVisitDao smallWebVisitDao = i4.SmallWebVisitDao(
|
||||
this as i3.SmallWebDatabase,
|
||||
);
|
||||
late final i5.WanderConsoleDao wanderConsoleDao = i5.WanderConsoleDao(
|
||||
this as i3.SmallWebDatabase,
|
||||
);
|
||||
i1.DefinitionsDrift get definitionsDrift => i6.ReadDatabaseContainer(
|
||||
this,
|
||||
).accessor<i1.DefinitionsDrift>(i1.DefinitionsDrift.new);
|
||||
@override
|
||||
Iterable<i0.TableInfo<i0.Table, Object?>> get allTables =>
|
||||
allSchemaEntities.whereType<i0.TableInfo<i0.Table, Object?>>();
|
||||
@override
|
||||
List<i0.DatabaseSchemaEntity> get allSchemaEntities => [
|
||||
smallWebItems,
|
||||
smallWebMemberships,
|
||||
i1.idxMembershipSourceMode,
|
||||
i1.idxMembershipItem,
|
||||
wanderConsoles,
|
||||
wanderConsoleNeighbors,
|
||||
smallWebVisits,
|
||||
i1.idxVisitMode,
|
||||
i1.idxVisitItem,
|
||||
];
|
||||
@override
|
||||
i0.StreamQueryUpdateRules get streamUpdateRules =>
|
||||
const i0.StreamQueryUpdateRules([
|
||||
i0.WritePropagation(
|
||||
on: i0.TableUpdateQuery.onTableName(
|
||||
'small_web_items',
|
||||
limitUpdateKind: i0.UpdateKind.delete,
|
||||
),
|
||||
result: [
|
||||
i0.TableUpdate('small_web_memberships', kind: i0.UpdateKind.delete),
|
||||
],
|
||||
),
|
||||
i0.WritePropagation(
|
||||
on: i0.TableUpdateQuery.onTableName(
|
||||
'wander_consoles',
|
||||
limitUpdateKind: i0.UpdateKind.delete,
|
||||
),
|
||||
result: [
|
||||
i0.TableUpdate(
|
||||
'wander_console_neighbors',
|
||||
kind: i0.UpdateKind.delete,
|
||||
),
|
||||
],
|
||||
),
|
||||
i0.WritePropagation(
|
||||
on: i0.TableUpdateQuery.onTableName(
|
||||
'small_web_items',
|
||||
limitUpdateKind: i0.UpdateKind.delete,
|
||||
),
|
||||
result: [
|
||||
i0.TableUpdate('small_web_visits', kind: i0.UpdateKind.delete),
|
||||
],
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
class $SmallWebDatabaseManager {
|
||||
final $SmallWebDatabase _db;
|
||||
$SmallWebDatabaseManager(this._db);
|
||||
i1.$SmallWebItemsTableManager get smallWebItems =>
|
||||
i1.$SmallWebItemsTableManager(_db, _db.smallWebItems);
|
||||
i1.$SmallWebMembershipsTableManager get smallWebMemberships =>
|
||||
i1.$SmallWebMembershipsTableManager(_db, _db.smallWebMemberships);
|
||||
i1.$WanderConsolesTableManager get wanderConsoles =>
|
||||
i1.$WanderConsolesTableManager(_db, _db.wanderConsoles);
|
||||
i1.$WanderConsoleNeighborsTableManager get wanderConsoleNeighbors =>
|
||||
i1.$WanderConsoleNeighborsTableManager(_db, _db.wanderConsoleNeighbors);
|
||||
i1.$SmallWebVisitsTableManager get smallWebVisits =>
|
||||
i1.$SmallWebVisitsTableManager(_db, _db.smallWebVisits);
|
||||
}
|
||||
|
||||
extension DefineFunctions on i7.CommonDatabase {
|
||||
void defineFunctions({
|
||||
required String Function(int, String?) lexoRankNext,
|
||||
required String Function(int, String?) lexoRankPrevious,
|
||||
required String Function(String?, String?) lexoRankReorderAfter,
|
||||
required String Function(String?, String?) lexoRankReorderBefore,
|
||||
}) {
|
||||
createFunction(
|
||||
functionName: 'lexo_rank_next',
|
||||
argumentCount: const i7.AllowedArgumentCount(2),
|
||||
function: (args) {
|
||||
final arg0 = args[0] as int;
|
||||
final arg1 = args[1] as String?;
|
||||
return lexoRankNext(arg0, arg1);
|
||||
},
|
||||
);
|
||||
createFunction(
|
||||
functionName: 'lexo_rank_previous',
|
||||
argumentCount: const i7.AllowedArgumentCount(2),
|
||||
function: (args) {
|
||||
final arg0 = args[0] as int;
|
||||
final arg1 = args[1] as String?;
|
||||
return lexoRankPrevious(arg0, arg1);
|
||||
},
|
||||
);
|
||||
createFunction(
|
||||
functionName: 'lexo_rank_reorder_after',
|
||||
argumentCount: const i7.AllowedArgumentCount(2),
|
||||
function: (args) {
|
||||
final arg0 = args[0] as String?;
|
||||
final arg1 = args[1] as String?;
|
||||
return lexoRankReorderAfter(arg0, arg1);
|
||||
},
|
||||
);
|
||||
createFunction(
|
||||
functionName: 'lexo_rank_reorder_before',
|
||||
argumentCount: const i7.AllowedArgumentCount(2),
|
||||
function: (args) {
|
||||
final arg0 = args[0] as String?;
|
||||
final arg1 = args[1] as String?;
|
||||
return lexoRankReorderBefore(arg0, arg1);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
import 'package:weblibre/data/database/converters/uri.dart';
|
||||
import 'package:weblibre/data/database/converters/string_list.dart';
|
||||
import 'package:weblibre/features/small_web/data/models/small_web_source_kind.dart';
|
||||
import 'package:weblibre/features/small_web/data/models/wander_console_source.dart';
|
||||
|
||||
CREATE TABLE small_web_items (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
url TEXT NOT NULL UNIQUE MAPPED BY `const UriConverter()`,
|
||||
title TEXT,
|
||||
domain TEXT NOT NULL,
|
||||
author TEXT,
|
||||
summary TEXT,
|
||||
published_at DATETIME,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) AS SmallWebItem;
|
||||
|
||||
CREATE TABLE small_web_memberships (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
item_id TEXT NOT NULL REFERENCES small_web_items(id) ON DELETE CASCADE,
|
||||
source_kind ENUM(SmallWebSourceKind) NOT NULL,
|
||||
mode TEXT,
|
||||
console_url TEXT MAPPED BY `const UriConverterNullable()`,
|
||||
categories TEXT NOT NULL DEFAULT '[]' MAPPED BY `const StringListConverter()`,
|
||||
fetched_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE(item_id, source_kind, mode, console_url)
|
||||
) AS SmallWebMembership;
|
||||
|
||||
CREATE INDEX idx_membership_source_mode ON small_web_memberships (source_kind, mode);
|
||||
CREATE INDEX idx_membership_item ON small_web_memberships (item_id);
|
||||
|
||||
CREATE TABLE wander_consoles (
|
||||
url TEXT NOT NULL PRIMARY KEY MAPPED BY `const UriConverter()`,
|
||||
wander_js_url TEXT NOT NULL MAPPED BY `const UriConverter()`,
|
||||
last_fetched_at DATETIME,
|
||||
last_fetch_failed BOOL,
|
||||
discovered_from_url TEXT MAPPED BY `const UriConverterNullable()`,
|
||||
source ENUM(WanderConsoleSource) NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) AS WanderConsole;
|
||||
|
||||
CREATE TABLE wander_console_neighbors (
|
||||
source_console_url TEXT NOT NULL REFERENCES wander_consoles(url) ON DELETE CASCADE,
|
||||
target_console_url TEXT NOT NULL,
|
||||
discovered_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (source_console_url, target_console_url)
|
||||
) AS WanderConsoleNeighbor;
|
||||
|
||||
CREATE TABLE small_web_visits (
|
||||
id TEXT NOT NULL PRIMARY KEY,
|
||||
item_id TEXT NOT NULL REFERENCES small_web_items(id) ON DELETE CASCADE,
|
||||
source_kind ENUM(SmallWebSourceKind) NOT NULL,
|
||||
mode TEXT,
|
||||
console_url TEXT MAPPED BY `const UriConverterNullable()`,
|
||||
visited_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) AS SmallWebVisit;
|
||||
|
||||
CREATE INDEX idx_visit_mode ON small_web_visits (source_kind, mode, visited_at);
|
||||
CREATE INDEX idx_visit_item ON small_web_visits (item_id);
|
||||
|
||||
getDiscoverableKagiItems:
|
||||
SELECT i.* FROM small_web_items i
|
||||
INNER JOIN small_web_memberships m ON m.item_id = i.id
|
||||
WHERE m.source_kind = :sourceKind
|
||||
AND m.mode = :mode
|
||||
AND (:category IS NULL OR EXISTS (
|
||||
SELECT 1 FROM json_each(m.categories) WHERE value = :category
|
||||
))
|
||||
AND i.id NOT IN (
|
||||
SELECT v.item_id FROM small_web_visits v
|
||||
WHERE v.source_kind = :sourceKind AND v.mode = :mode
|
||||
ORDER BY v.visited_at DESC LIMIT 20
|
||||
);
|
||||
|
||||
getRecentVisits:
|
||||
SELECT v.*, i.url, i.title, i.domain
|
||||
FROM small_web_visits v
|
||||
INNER JOIN small_web_items i ON i.id = v.item_id
|
||||
WHERE v.source_kind = :sourceKind
|
||||
AND ((:mode IS NULL AND v.mode IS NULL) OR v.mode = :mode)
|
||||
ORDER BY v.visited_at DESC
|
||||
LIMIT :limit;
|
||||
|
||||
getDiscoveredConsoleUrls:
|
||||
SELECT url FROM wander_consoles ORDER BY created_at DESC LIMIT :limit;
|
||||
|
||||
getWanderPagesForConsole:
|
||||
SELECT i.* FROM small_web_items i
|
||||
INNER JOIN small_web_memberships m ON m.item_id = i.id
|
||||
WHERE m.source_kind = :sourceKind AND m.console_url = CAST(:consoleUrl AS TEXT);
|
||||
|
||||
getConsoleNeighborCount:
|
||||
SELECT COUNT(*) AS c FROM wander_console_neighbors WHERE source_console_url = :consoleUrl;
|
||||
|
||||
getAllModeItemCounts:
|
||||
SELECT source_kind, mode, COUNT(*) AS c
|
||||
FROM small_web_memberships
|
||||
GROUP BY source_kind, mode;
|
||||
|
||||
getRecentVisitItemIds:
|
||||
SELECT DISTINCT item_id FROM small_web_visits
|
||||
WHERE source_kind = :sourceKind
|
||||
AND ((:mode IS NULL AND mode IS NULL) OR mode = :mode)
|
||||
ORDER BY visited_at DESC
|
||||
LIMIT :limit;
|
||||
|
||||
getNeighborConsolesWithPageCounts:
|
||||
SELECT wc.url, wc.last_fetched_at, wc.last_fetch_failed,
|
||||
(SELECT COUNT(*) FROM small_web_memberships m
|
||||
WHERE m.source_kind = :sourceKind AND m.console_url = CAST(wc.url AS TEXT)) AS page_count
|
||||
FROM wander_console_neighbors n
|
||||
INNER JOIN wander_consoles wc ON CAST(wc.url AS TEXT) = n.target_console_url
|
||||
WHERE n.source_console_url = :sourceConsoleUrl
|
||||
AND COALESCE(wc.last_fetch_failed, 0) = 0
|
||||
ORDER BY page_count DESC;
|
||||
|
||||
getAllConsolesWithPageCounts:
|
||||
SELECT wc.url, wc.last_fetched_at, wc.last_fetch_failed,
|
||||
(SELECT COUNT(*) FROM small_web_memberships m
|
||||
WHERE m.source_kind = :sourceKind AND m.console_url = CAST(wc.url AS TEXT)) AS page_count
|
||||
FROM wander_consoles wc
|
||||
WHERE COALESCE(wc.last_fetch_failed, 0) = 0
|
||||
AND (:query = '' OR CAST(wc.url AS TEXT) LIKE '%' || :query || '%')
|
||||
ORDER BY page_count DESC;
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user