From a49d5542567cd533694c3f57943a006dc256d8cb Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Wed, 19 Sep 2018 17:33:20 -0400 Subject: [PATCH] Prefix tables with just pterotype --- inc/activities.php | 10 +++++----- inc/actors.php | 8 ++++---- inc/blocks.php | 2 +- inc/following.php | 2 +- inc/inbox.php | 4 ++-- inc/likes.php | 2 +- inc/migrations.php | 30 +++++++++++++++--------------- inc/objects.php | 16 ++++++++-------- inc/outbox.php | 17 +++++++---------- 9 files changed, 44 insertions(+), 47 deletions(-) diff --git a/inc/activities.php b/inc/activities.php index 6976b15..5102101 100644 --- a/inc/activities.php +++ b/inc/activities.php @@ -4,7 +4,7 @@ namespace activities; function get_activity( $id ) { global $wpdb; $activity_json = $wpdb->get_var( $wpdb->prepare( - 'SELECT activity FROM pterotype_activitypub_activities WHERE id = %d', $id + 'SELECT activity FROM pterotype_activities WHERE id = %d', $id ) ); if ( is_null( $activity_json ) ) { return new \WP_Error( @@ -18,7 +18,7 @@ function get_activity( $id ) { function get_activity_by_activitypub_id( $activitypub_id ) { global $wpdb; $activity_json = $wpdb->get_var( $wpdb->prepare( - 'SELECT activity FROM pterotype_activitypub_activities WHERE id = %s', $activitypub_id + 'SELECT activity FROM pterotype_activities WHERE id = %s', $activitypub_id ) ); if ( is_null( $activity_json ) ) { return new \WP_Error( @@ -49,7 +49,7 @@ function persist_activity( $activity ) { ); } $activitypub_id = $activity['id']; - $wpdb->insert( 'pterotype_activitypub_activities', array( + $wpdb->insert( 'pterotype_activities', array( 'activitypub_id' => $activitypub_id, 'activity' => wp_json_encode( $activity ) ) ); @@ -58,7 +58,7 @@ function persist_activity( $activity ) { function create_local_activity( $activity ) { global $wpdb; - $res = $wpdb->insert( 'pterotype_activitypub_activities', array( + $res = $wpdb->insert( 'pterotype_activities', array( 'activity' => wp_json_encode( $activity ) ) ); if ( !$res ) { @@ -70,7 +70,7 @@ function create_local_activity( $activity ) { $activity_url = get_rest_url( null, sprintf( '/pterotype/v1/activity/%d', $id ) ); $activity['id'] = $activity_url; $res = $wpdb->replace( - 'pterotype_activitypub_activities', + 'pterotype_activities', array( 'id' => $activity_id, 'activitypub_id' => $activity_url, diff --git a/inc/actors.php b/inc/actors.php index f028cd5..c23c8fb 100644 --- a/inc/actors.php +++ b/inc/actors.php @@ -4,7 +4,7 @@ namespace actors; function get_actor( $id ) { global $wpdb; $row = $wpdb->get_row( $wpdb->prepare( - 'SELECT * FROM pterotype_activitypub_actors WHERE id = %d', $id + 'SELECT * FROM pterotype_actors WHERE id = %d', $id ) ); return get_user_from_row( $row ); } @@ -12,7 +12,7 @@ function get_actor( $id ) { function get_actor_by_slug ( $slug ) { global $wpdb; $row = $wpdb->get_row( $wpdb->prepare( - 'SELECT * FROM pterotype_activitypub_actors WHERE slug = %s', $slug + 'SELECT * FROM pterotype_actors WHERE slug = %s', $slug ) ); return get_actor_from_row( $row ); } @@ -20,7 +20,7 @@ function get_actor_by_slug ( $slug ) { function get_actor_id( $slug ) { global $wpdb; return $wpdb->get_var( $wpdb->prepare( - "SELECT slug FROM pterotype_activitypub_actors WHERE slug = %s", $slug + "SELECT slug FROM pterotype_actors WHERE slug = %s", $slug ) ); } @@ -78,7 +78,7 @@ function initialize_user_actors() { function create_actor_from_user( $user_slug ) { global $wpdb; $wpdb->query( $wpdb->prepare( - "INSERT IGNORE INTO pterotype_activitypub_actors(slug, type) VALUES(%s, 'user')", $user_slug + "INSERT IGNORE INTO pterotype_actors(slug, type) VALUES(%s, 'user')", $user_slug ) ); } ?> diff --git a/inc/blocks.php b/inc/blocks.php index f1ddff3..881b05b 100644 --- a/inc/blocks.php +++ b/inc/blocks.php @@ -10,7 +10,7 @@ get ignored function create_block( $actor_id, $blocked_actor_url ) { global $wpdb; $res = $wpdb->insert( - 'pterotype_activitypub_blocks', + 'pterotype_blocks', array( 'actor_id' => $actor_id, 'blocked_actor_url' => $blocked_actor_url ) ); if ( !$res ) { diff --git a/inc/following.php b/inc/following.php index dbe108c..28ac075 100644 --- a/inc/following.php +++ b/inc/following.php @@ -7,7 +7,7 @@ $FOLLOWING = 'FOLLOWING'; function request_follow( $actor_id, $object_id ) { global $wpdb; return $wpdb->insert( - 'pterotype_activitypub_following', + 'pterotype_following', array( 'actor_id' => $actor_id, 'object_id' => wp_json_encode( $object ), 'state' => $PENDING diff --git a/inc/inbox.php b/inc/inbox.php index 54b361a..96780ec 100644 --- a/inc/inbox.php +++ b/inc/inbox.php @@ -65,12 +65,12 @@ function create_inbox_table() { global $wpdb; $wpdb->query( " - CREATE TABLE IF NOT EXISTS pterotype_activitypub_inbox( + CREATE TABLE IF NOT EXISTS pterotype_inbox( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, actor_id UNSIGNED INT NOT NULL, activity_id INT UNSIGNED NOT NULL, FOREIGN KEY inbox_activity_fk(activity_id) - REFERENCES pterotype_activitypub_activities(id) + REFERENCES pterotype_activities(id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; " diff --git a/inc/likes.php b/inc/likes.php index 480944c..92358d1 100644 --- a/inc/likes.php +++ b/inc/likes.php @@ -4,7 +4,7 @@ namespace likes; function create_like( $actor_id, $object_id ) { global $wpdb; return $wpdb->insert( - 'pterotype_activitypub_likes', array( 'actor_id' => $actor_id, 'object_id' => $object_id ) + 'pterotype_likes', array( 'actor_id' => $actor_id, 'object_id' => $object_id ) ); } ?> diff --git a/inc/migrations.php b/inc/migrations.php index 579bbc6..eea54ce 100644 --- a/inc/migrations.php +++ b/inc/migrations.php @@ -25,7 +25,7 @@ function migration_0_0_1() { global $wpdb; $wpdb->query( " - CREATE TABLE pterotype_activitypub_activities ( + CREATE TABLE pterotype_activities ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, activitypub_id VARCHAR(255) UNIQUE NOT NULL, activity TEXT NOT NULL @@ -36,12 +36,12 @@ function migration_0_0_1() { $wpdb->query( " CREATE UNIQUE INDEX ACTIVITIES_ACTIVITYPUB_ID_INDEX - ON pterotype_activitypub_activities (activitypub_id); + ON pterotype_activities (activitypub_id); " ); $wpdb->query( " - CREATE TABLE pterotype_activitypub_objects ( + CREATE TABLE pterotype_objects ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, activitypub_id VARCHAR(255) UNIQUE NOT NULL, object TEXT NOT NULL @@ -52,24 +52,24 @@ function migration_0_0_1() { $wpdb->query( " CREATE UNIQUE INDEX OBJECT_ACTIVITYPUB_ID_INDEX - ON pterotype_activitypub_objects (activitypub_id); + ON pterotype_objects (activitypub_id); " ); $wpdb->query( " - CREATE TABLE pterotype_activitypub_outbox ( + CREATE TABLE pterotype_outbox ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, actor_id INT UNSIGNED NOT NULL, activity_id INT UNSIGNED NOT NULL, FOREIGN KEY outbox_activity_fk(activity_id) - REFERENCES pterotype_activitypub_activities(id) + REFERENCES pterotype_activities(id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ); $wpdb->query( " - CREATE TABLE pterotype_activitypub_actors( + CREATE TABLE pterotype_actors( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, slug VARCHAR(64) UNIQUE NOT NULL, type VARCHAR(64) NOT NULL @@ -79,40 +79,40 @@ function migration_0_0_1() { ); $wpdb->query( " - CREATE TABLE pterotype_activitypub_likes ( + CREATE TABLE pterotype_likes ( actor_id INT UNSIGNED NOT NULL, object_id INT UNSIGNED NOT NULL, PRIMARY KEY (actor_id, object_id), FOREIGN KEY likes_actor_fk(actor_id) - REFERENCES pterotype_activitypub_actors(id), + REFERENCES pterotype_actors(id), FOREIGN KEY likes_object_fk(object_id) - REFERENCES pterotype_activitypub_objects(id) + REFERENCES pterotype_objects(id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ); $wpdb->query( " - CREATE TABLE pterotype_activitypub_following( + CREATE TABLE pterotype_following( actor_id INT UNSIGNED NOT NULL, object_id INT UNSIGNED NOT NULL, state VARCHAR(64) NOT NULL, PRIMARY KEY (actor_id, object_id), FOREIGN KEY following_actor_fk(actor_id) - REFERENCES pterotype_activitypub_actors(id), + REFERENCES pterotype_actors(id), FOREIGN KEY following_object_fk(object_id) - REFERENCES pterotype_activitypub_objects(id) + REFERENCES pterotype_objects(id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; " ); $wpdb->query( " - CREATE TABLE pterotype_activitypub_blocks( + CREATE TABLE pterotype_blocks( actor_id INT UNSIGNED NOT NULL, blocked_actor_url TEXT NOT NULL, FOREIGN KEY blocks_actor_fk(actor_id) - REFERENCES pterotype_activitypub_actors(id) + REFERENCES pterotype_actors(id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; " diff --git a/inc/objects.php b/inc/objects.php index e0c1285..a4f6440 100644 --- a/inc/objects.php +++ b/inc/objects.php @@ -6,7 +6,7 @@ namespace objects; function create_local_object( $object ) { global $wpdb; - $res = $wpdb->insert( 'pterotype_activitypub_objects', array( + $res = $wpdb->insert( 'pterotype_objects', array( 'object' => wp_json_encode( $object ) ) ); if ( !$res ) { @@ -18,7 +18,7 @@ function create_local_object( $object ) { $object_url = get_rest_url( null, sprintf( '/pterotype/v1/object/%d', $object_id ) ); $object['id'] = $object_url; $res = $wpdb->replace( - 'pterotype_activitypub_objects', + 'pterotype_objects', array ( 'id' => $object_id, 'activitypub_id' => $object_url, @@ -44,12 +44,12 @@ function upsert_object( $object ) { ); } $row = $wpdb->get_row( $wpdb->prepare( - 'SELECT * FROM pterotype_activitypub_objects WHERE activitypub_url = %s', $object['id'] + 'SELECT * FROM pterotype_objects WHERE activitypub_url = %s', $object['id'] ) ); $res = true; if ( $row === null ) { $res = $wpdb->insert( - 'pterotype_activitypub_objects', + 'pterotype_objects', array( 'activitypub_id' => $object['id'], 'object' => wp_json_encode( $object ) @@ -57,7 +57,7 @@ function upsert_object( $object ) { ); } else { $res = $wpdb->replace( - 'pterotype_activitypub_objects', + 'pterotype_objects', array( 'id' => $row->id, 'activitypub_id' => $object['id'], @@ -103,7 +103,7 @@ function update_object( $object ) { function get_object( $id ) { global $wpdb; $object_json = $wpdb->get_var( $wpdb->prepare( - 'SELECT object FROM pterotype_activitypub_objects WHERE id = %d', $id + 'SELECT object FROM pterotype_objects WHERE id = %d', $id ) ); if ( is_null( $object_json ) ) { return new \WP_Error( @@ -116,7 +116,7 @@ function get_object( $id ) { function get_object_by_activitypub_id( $activitypub_id ) { global $wpdb; $object_json = $wpdb->get_var( $wpdb->prepare( - 'SELECT object FROM pterotype_activitypub_objects WHERE activitypub_id = %s', $activitypub_id + 'SELECT object FROM pterotype_objects WHERE activitypub_id = %s', $activitypub_id ) ); if ( is_null( $object_json ) ) { return new \WP_Error( @@ -136,7 +136,7 @@ function delete_object( $object ) { ); } $activitypub_id = $object['id']; - $res = $wpdb->delete( 'pterotype_activitypub_objects', array( 'activitypub_id' => $id ), '%s' ); + $res = $wpdb->delete( 'pterotype_objects', array( 'activitypub_id' => $id ), '%s' ); if ( !$res ) { return new \WP_Error( 'db_error', __( 'Error deleting object', 'pterotype' ) ); } diff --git a/inc/outbox.php b/inc/outbox.php index 459d73f..9a2384b 100644 --- a/inc/outbox.php +++ b/inc/outbox.php @@ -91,15 +91,12 @@ function get_outbox( $actor_slug ) { // TODO what sort of joins should these be? $results = $wpdb->get_results( $wpdb->prepare( " - SELECT pterotype_activitypub_activities.activity - FROM pterotype_activitypub_outbox - JOIN pterotype_activitypub_actors - ON pterotype_activitypub_actors.id - = pterotype_activitypub_outbox.actor_id - JOIN pterotype_activitypub_activities - ON pterotype_activitypub_activities.id - = pterotype_activitypub_outbox.activity_id - WHERE pterotype_pterotype_activitypub_outbox.actor_id = %d + SELECT pterotype_activities.activity FROM pterotype_outbox + JOIN pterotype_actors + ON pterotype_actors.id = pterotype_outbox.actor_id + JOIN pterotype_activities + ON pterotype_activities.id = pterotype_outbox.activity_id + WHERE pterotype_pterotype_outbox.actor_id = %d ", $actor_id ) ); @@ -123,7 +120,7 @@ function persist_activity( $actor_slug, $activity ) { $activity = \activities\create_local_activity( $activity ); $activity_id = $wpdb->insert_id; $actor_id = \actors\get_actor_id( $actor_slug ); - $wpdb->insert( 'pterotype_activitypub_outbox', array( + $wpdb->insert( 'pterotype_outbox', array( 'actor_id' => $actor_id, 'activity_id' => $activity_id, ) );