more inappropriation

This commit is contained in:
Joe Ardent 2023-07-08 22:00:26 -07:00
parent b593711d11
commit 840fba6e92
9 changed files with 45 additions and 38 deletions

2
.env
View file

@ -1 +1 @@
DATABASE_URL=sqlite://${HOME}/.witch-watch.db
DATABASE_URL=sqlite://${HOME}/.what2watch.db

View file

@ -1,12 +1,16 @@
-- indices
drop index if exists user_dex;
drop index if exists watch_dex;
drop index if exists ww_dex;
drop index if exists note_dex;
drop index if exists user_username_dex;
drop index if exists user_email_dex;
drop index if exists watch_title_dex;
drop index if exists witch_added_by_dex;
drop index if exists quests_user_dex;
drop index if exists quests_watch_dex;
drop index if exists note_user_dex;
drop index if exists note_watch_dex;
-- tables
drop table if exists watch_quest;
drop table if exists watch_quests;
drop table if exists watch_notes;
drop table if exists covens;
drop table if exists follows;
drop table if exists users;
drop table if exists watches;

View file

@ -28,7 +28,7 @@ create table if not exists watches (
);
-- table of what people want to watch
create table if not exists watch_quest (
create table if not exists watch_quests (
user blob not null,
watch blob not null,
priority int, -- 1-5 how much do you want to watch it
@ -44,9 +44,9 @@ create table if not exists watch_quest (
-- friend lists; this should really be a graph db, maybe the whole thing should be
-- TODO: look into replacing sqlite with https://www.cozodb.org/
create table if not exists covens (
create table if not exists follows (
user blob not null primary key,
coven blob, -- possibly empty friends list in some app-specific format
follows blob, -- possibly empty friends list in some app-specific format
last_updated int not null default (unixepoch()),
foreign key (user) references users (id) on delete cascade on update no action
);
@ -62,12 +62,12 @@ create table if not exists watch_notes (
foreign key (watch) references watches (id) on delete cascade on update no action
);
-- indices, not needed for covens
-- indices, not needed for follows
create index if not exists user_username_dex on users (username);
create index if not exists user_email_dex on users (email);
create index if not exists watch_title_dex on watches (title);
create index if not exists watch_added_by_dex on watches (added_by);
create index if not exists ww_user_dex on watch_quest (user);
create index if not exists ww_watch_dex on watch_quest (watch);
create index if not exists quests_user_dex on watch_quests (user);
create index if not exists quests_watch_dex on watch_quests (watch);
create index if not exists note_user_dex on watch_notes (user);
create index if not exists note_watch_dex on watch_notes (watch);

View file

@ -1,5 +1,5 @@
drop trigger if exists update_last_updated_users;
drop trigger if exists update_last_updated_watches;
drop trigger if exists update_last_updated_watch_quest;
drop trigger if exists update_last_updated_covens;
drop trigger if exists update_last_updated_watch_quests;
drop trigger if exists update_last_updated_follows;
drop trigger if exists update_last_updated_watch_notes;

View file

@ -12,18 +12,18 @@ BEGIN
update watches set last_updated = (select unixepoch()) where id=NEW.id;
END;
create trigger if not exists update_last_updated_watch_quest
after update on watch_quest
create trigger if not exists update_last_updated_watch_quests
after update on watch_quests
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
BEGIN
update watch_quest set last_updated = (select unixepoch()) where id=NEW.id;
update watch_quests set last_updated = (select unixepoch()) where id=NEW.id;
END;
create trigger if not exists update_last_updated_covens
after update on covens
create trigger if not exists update_last_updated_follows
after update on follows
when OLD.last_updated = NEW.last_updated or OLD.last_updated is null
BEGIN
update covens set last_updated = (select unixepoch()) where id=NEW.id;
update follows set last_updated = (select unixepoch()) where id=NEW.id;
END;
create trigger if not exists update_last_updated_watch_notes

View file

@ -22,16 +22,16 @@ async fn main() {
.await
.expect("could not open movies db");
let ww_db = get_db_pool().await;
let w2w_db = get_db_pool().await;
let start = std::time::Instant::now();
add_omega_watches(&ww_db, &movie_db).await.unwrap();
add_omega_watches(&w2w_db, &movie_db).await.unwrap();
let end = std::time::Instant::now();
let dur = (end - start).as_secs_f32();
let rows: i32 = sqlx::query_scalar("select count(*) from watches")
.fetch_one(&ww_db)
.fetch_one(&w2w_db)
.await
.unwrap();

View file

@ -36,21 +36,21 @@ async fn main() {
.connect_with(opts)
.await
.expect("could not open movies db");
let ww_db = get_db_pool().await;
let w2w_db = get_db_pool().await;
let users = &gen_users(num_users, &words, &ww_db).await;
let movies = &add_omega_watches(&ww_db, &movie_db).await.unwrap();
let users = &gen_users(num_users, &words, &w2w_db).await;
let movies = &add_omega_watches(&w2w_db, &movie_db).await.unwrap();
let rng = &mut thread_rng();
let normal = Normal::new(mpu, mpu / 10.0).unwrap();
let start = std::time::Instant::now();
for &user in users {
add_quests(user, movies, &ww_db, rng, normal).await;
add_quests(user, movies, &w2w_db, rng, normal).await;
}
let end = std::time::Instant::now();
let rows: i32 = sqlx::query_scalar("select count(*) from watch_quest")
.fetch_one(&ww_db)
let rows: i32 = sqlx::query_scalar("select count(*) from watch_quests")
.fetch_one(&w2w_db)
.await
.unwrap();
let dur = (end - start).as_secs_f32();
@ -100,7 +100,7 @@ async fn gen_users(num: usize, words: &[&str], pool: &SqlitePool) -> Vec<DbId> {
async fn add_quests<R: Rng>(
user: DbId,
movies: &[DbId],
ww_db: &SqlitePool,
w2w_db: &SqlitePool,
rng: &mut R,
normal: Normal<f32>,
) {
@ -121,7 +121,7 @@ async fn add_quests<R: Rng>(
.map(tokio_retry::strategy::jitter)
.take(3);
let db = ww_db.clone();
let db = w2w_db.clone();
tasks.spawn(async move {
let movies = quests;
(

View file

@ -52,7 +52,7 @@ impl From<&ImportMovieOmega> for Watch {
// utility functions for building CLI tools, currently just for benchmarking
//-************************************************************************
pub async fn add_watch_quests(pool: &SqlitePool, quests: &[WatchQuest]) -> Result<(), ()> {
let mut builder = sqlx::QueryBuilder::new("insert into watch_quest (user, watch) ");
let mut builder = sqlx::QueryBuilder::new("insert into watch_quests (user, watch) ");
builder.push_values(quests, |mut b, quest| {
let user = quest.user;
let watch = quest.watch;
@ -84,8 +84,11 @@ pub async fn add_users(db_pool: &SqlitePool, users: &[User]) -> Result<(), ()> {
Ok(())
}
pub async fn add_omega_watches(ww_db: &SqlitePool, movie_db: &SqlitePool) -> Result<Vec<DbId>, ()> {
ensure_omega(ww_db).await;
pub async fn add_omega_watches(
w2w_db: &SqlitePool,
movie_db: &SqlitePool,
) -> Result<Vec<DbId>, ()> {
ensure_omega(w2w_db).await;
let movies: Vec<ImportMovieOmega> = sqlx::query_as(MOVIE_QUERY)
.fetch_all(movie_db)
@ -114,7 +117,7 @@ pub async fn add_omega_watches(ww_db: &SqlitePool, movie_db: &SqlitePool) -> Res
});
let q = builder.build();
q.execute(ww_db).await.map_err(|_| ())?;
q.execute(w2w_db).await.map_err(|_| ())?;
}
Ok(ids)

View file

@ -18,13 +18,13 @@ use crate::{
//-************************************************************************
const GET_SAVED_WATCHES_QUERY: &str =
"select * from watches left join watch_quest on $1 = watch_quest.user and watches.id = watch_quest.watch";
"select * from watches left join watch_quests on $1 = watch_quests.user and watches.id = watch_quests.watch";
const GET_WATCH_QUERY: &str = "select * from watches where id = $1";
const ADD_WATCH_QUERY: &str = "insert into watches (id, title, kind, release_date, metadata_url, added_by) values ($1, $2, $3, $4, $5, $6)";
const ADD_WATCH_QUEST_QUERY: &str =
"insert into watch_quest (user, watch, public, watched) values ($1, $2, $3, $4)";
"insert into watch_quests (user, watch, public, watched) values ($1, $2, $3, $4)";
const EMPTY_SEARCH_QUERY_STRUCT: SearchQuery = SearchQuery {
title: None,