···55import ThemeToggle from '@/components/ThemeToggle';
66import ClientOnly from '@/components/ClientOnly';
77import ProfileSearch from '@/components/ProfileSearch';
88+import { Analytics } from "@vercel/analytics/react"
89910// Configure this layout as having dynamic runtime to fix SSR issues with theme
1011export const dynamic = 'force-dynamic';
···6465 <main>{children}</main>
6566 </ThemeProvider>
6667 </AuthProvider>
6868+ <Analytics />
6769 </body>
6870 </html>
6971 );
-26
execute_raw_query.sql
···11--- Create a function to execute raw SQL queries safely
22--- This allows direct SQL execution for better performance and reliability
33-44-CREATE OR REPLACE FUNCTION execute_raw_query(raw_query TEXT)
55-RETURNS JSONB
66-LANGUAGE plpgsql
77-SECURITY DEFINER -- This runs with the privileges of the function creator
88-AS $$
99-DECLARE
1010- result JSONB;
1111-BEGIN
1212- -- Only allow SELECT queries for security
1313- IF position('SELECT' in upper(raw_query)) != 1 THEN
1414- RAISE EXCEPTION 'Only SELECT queries are allowed';
1515- END IF;
1616-1717- -- Execute the query and convert result to JSON
1818- EXECUTE 'SELECT json_agg(t) FROM (' || raw_query || ') t' INTO result;
1919-2020- -- Return empty array instead of null if no results
2121- RETURN COALESCE(result, '[]'::jsonb);
2222-END;
2323-$$;
2424-2525--- Test the function
2626-SELECT execute_raw_query('SELECT id, did, handle, text FROM flushing_records ORDER BY id DESC LIMIT 3');
-15
get_latest_entries.sql
···11--- Create a function to get the latest flushing entries
22--- This function will be called from our API
33-CREATE OR REPLACE FUNCTION get_latest_entries(max_entries INTEGER)
44-RETURNS SETOF flushing_records
55-LANGUAGE SQL
66-AS $$
77- -- Direct SQL query to get the latest entries by ID
88- -- This bypasses any caching and pagination issues
99- SELECT * FROM flushing_records
1010- ORDER BY id DESC
1111- LIMIT max_entries;
1212-$$;
1313-1414--- Test the function with a limit of 5 entries
1515-SELECT * FROM get_latest_entries(5);
-14
total_flush_count.sql
···11--- Create a simple function to get the total count of records
22--- This uses a different counting mechanism to avoid any potential caching issues
33-44-CREATE OR REPLACE FUNCTION get_total_flush_count()
55-RETURNS INTEGER
66-LANGUAGE SQL
77-AS $$
88- -- Simple, direct query to count all records
99- SELECT COUNT(id)::INTEGER
1010- FROM flushing_records;
1111-$$;
1212-1313--- Test the function
1414-SELECT get_total_flush_count();