From 088757c3a6eeb71db6da793bbeb47d9c762b309d Mon Sep 17 00:00:00 2001 From: Dan Notestein <dan@syncad.com> Date: Wed, 22 Jan 2025 15:10:08 -0500 Subject: [PATCH] Remove 'preview' field from database schema and related SQL queries --- README.md | 2 +- hive/db/schema.py | 1 - hive/db/sql_scripts/get_post_view_by_id.sql | 4 ---- hive/indexer/post_data_cache.py | 8 +++----- 4 files changed, 4 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 459768fd3..837faa0e7 100644 --- a/README.md +++ b/README.md @@ -386,7 +386,7 @@ sync will create the database indexes necessary for hive server to efficiently p ### Cache layer Synchronizes the latest state of posts and users, allowing us to serve discussions and lists of posts with all expected -information (title, preview, image, payout, votes, etc) without needing `hived`. This layer is first built once the +information (title, image, payout, votes, etc) without needing `hived`. This layer is first built once the initial core indexing is complete. Incoming blocks trigger cache updates (including recalculation of trending score) for any posts referenced in `comment` or `vote` operations. There is a sweep to paid out posts to ensure they are updated in full with their final state. diff --git a/hive/db/schema.py b/hive/db/schema.py index 4f8de5901..31275d7e4 100644 --- a/hive/db/schema.py +++ b/hive/db/schema.py @@ -177,7 +177,6 @@ def build_metadata(): sa.Column('hive_rowid', sa.BigInteger, server_default=hive_rowid_seq.next_value(), nullable=False), sa.Column('id', sa.Integer, primary_key=True, autoincrement=False), sa.Column('title', VARCHAR(512), nullable=False, server_default=''), - sa.Column('preview', VARCHAR(1024), nullable=False, server_default=''), # first 1k of 'body' sa.Column('img_url', VARCHAR(1024), nullable=False, server_default=''), # first 'image' from 'json' sa.Column('body', TEXT, nullable=False, server_default=''), sa.Column('json', TEXT, nullable=False, server_default=''), diff --git a/hive/db/sql_scripts/get_post_view_by_id.sql b/hive/db/sql_scripts/get_post_view_by_id.sql index ed3ae1b38..1d9e5b362 100644 --- a/hive/db/sql_scripts/get_post_view_by_id.sql +++ b/hive/db/sql_scripts/get_post_view_by_id.sql @@ -13,7 +13,6 @@ CREATE TYPE hivemind_app.get_post_view_by_id_return_t AS( title character varying(512), body text, img_url character varying(1024), - preview character varying(1024), category character varying(255) COLLATE pg_catalog."C", category_id integer, depth smallint, @@ -84,7 +83,6 @@ BEGIN hpd.title, hpd.body, hpd.img_url, - hpd.preview, hcd.category, hp.category_id, hp.depth, @@ -219,7 +217,6 @@ CREATE TYPE hivemind_app.get_full_post_view_by_id_return_t AS( title character varying(512), body text, img_url character varying(1024), - preview character varying(1024), category character varying(255) COLLATE pg_catalog."C", category_id integer, depth smallint, @@ -291,7 +288,6 @@ BEGIN hpd.title, hpd.body, hpd.img_url, - hpd.preview, hcd.category, hp.category_id, hp.depth, diff --git a/hive/indexer/post_data_cache.py b/hive/indexer/post_data_cache.py index f78b5b4e8..7a0c4b95a 100644 --- a/hive/indexer/post_data_cache.py +++ b/hive/indexer/post_data_cache.py @@ -51,10 +51,9 @@ class PostDataCache(DbAdapterHolder): for k, data in cls._data.items(): title = 'NULL' if data['title'] is None else f"{escape_characters(data['title'])}" body = 'NULL' if data['body'] is None else f"{escape_characters(data['body'])}" - preview = 'NULL' if data['body'] is None else f"{escape_characters(data['body'][0:1024])}" json = 'NULL' if data['json'] is None else f"{escape_characters(data['json'])}" img_url = 'NULL' if data['img_url'] is None else f"{escape_characters(data['img_url'])}" - value = f"({k},{title},{preview},{img_url},{body},{json})" + value = f"({k},{title},{img_url},{body},{json})" if data['is_new_post']: values_insert.append(value) else: @@ -64,7 +63,7 @@ class PostDataCache(DbAdapterHolder): if len(values_insert) > 0: sql = f""" INSERT INTO - {SCHEMA_NAME}.hive_post_data (id, title, preview, img_url, body, json) + {SCHEMA_NAME}.hive_post_data (id, title, img_url, body, json) VALUES """ sql += ','.join(values_insert) @@ -77,7 +76,6 @@ class PostDataCache(DbAdapterHolder): sql = f""" UPDATE {SCHEMA_NAME}.hive_post_data AS hpd SET title = COALESCE( data_source.title, hpd.title ), - preview = COALESCE( data_source.preview, hpd.preview ), img_url = COALESCE( data_source.img_url, hpd.img_url ), body = COALESCE( data_source.body, hpd.body ), json = COALESCE( data_source.json, hpd.json ) @@ -87,7 +85,7 @@ class PostDataCache(DbAdapterHolder): """ sql += ','.join(values_update) sql += """ - ) AS T(id, title, preview, img_url, body, json) + ) AS T(id, title, img_url, body, json) ) AS data_source WHERE hpd.id = data_source.id """ -- GitLab