@@ -49,7 +49,7 @@ public function add_update( string $room, $update ): bool {
4949 $ result = $ wpdb ->insert (
5050 $ wpdb ->sync_updates ,
5151 array (
52- 'room_hash ' => md5 ( $ room ) ,
52+ 'room ' => $ room ,
5353 'update_value ' => wp_json_encode ( $ update ),
5454 'created_at ' => current_time ( 'mysql ' , true ),
5555 ),
@@ -71,7 +71,7 @@ public function add_update( string $room, $update ): bool {
7171 * @return array<int, mixed> Awareness state.
7272 */
7373 public function get_awareness_state ( string $ room ): array {
74- $ awareness = get_transient ( 'sync_awareness_ ' . md5 ( $ room ) );
74+ $ awareness = get_transient ( 'sync_awareness_ ' . $ room );
7575
7676 if ( ! is_array ( $ awareness ) ) {
7777 return array ();
@@ -125,13 +125,11 @@ public function get_update_count( string $room ): int {
125125 public function get_updates_after_cursor ( string $ room , int $ cursor ): array {
126126 global $ wpdb ;
127127
128- $ room_hash = md5 ( $ room );
129-
130128 // Snapshot the current max ID for this room to define a stable upper bound.
131129 $ max_id = (int ) $ wpdb ->get_var (
132130 $ wpdb ->prepare (
133- "SELECT COALESCE( MAX( id ), 0 ) FROM {$ wpdb ->sync_updates } WHERE room_hash = %s " ,
134- $ room_hash
131+ "SELECT COALESCE( MAX( id ), 0 ) FROM {$ wpdb ->sync_updates } WHERE room = %s " ,
132+ $ room
135133 )
136134 );
137135
@@ -146,17 +144,17 @@ public function get_updates_after_cursor( string $room, int $cursor ): array {
146144 // Bounded by max_id to stay consistent with the snapshot window above.
147145 $ this ->room_update_counts [ $ room ] = (int ) $ wpdb ->get_var (
148146 $ wpdb ->prepare (
149- "SELECT COUNT(*) FROM {$ wpdb ->sync_updates } WHERE room_hash = %s AND id <= %d " ,
150- $ room_hash ,
147+ "SELECT COUNT(*) FROM {$ wpdb ->sync_updates } WHERE room = %s AND id <= %d " ,
148+ $ room ,
151149 $ max_id
152150 )
153151 );
154152
155153 // Fetch updates after the cursor up to the snapshot boundary.
156154 $ rows = $ wpdb ->get_results (
157155 $ wpdb ->prepare (
158- "SELECT update_value FROM {$ wpdb ->sync_updates } WHERE room_hash = %s AND id > %d AND id <= %d ORDER BY id ASC " ,
159- $ room_hash ,
156+ "SELECT update_value FROM {$ wpdb ->sync_updates } WHERE room = %s AND id > %d AND id <= %d ORDER BY id ASC " ,
157+ $ room ,
160158 $ cursor ,
161159 $ max_id
162160 )
@@ -193,8 +191,8 @@ public function remove_updates_before_cursor( string $room, int $cursor ): bool
193191
194192 $ result = $ wpdb ->query (
195193 $ wpdb ->prepare (
196- "DELETE FROM {$ wpdb ->sync_updates } WHERE room_hash = %s AND id < %d " ,
197- md5 ( $ room ) ,
194+ "DELETE FROM {$ wpdb ->sync_updates } WHERE room = %s AND id < %d " ,
195+ $ room ,
198196 $ cursor
199197 )
200198 );
@@ -216,6 +214,6 @@ public function remove_updates_before_cursor( string $room, int $cursor ): bool
216214 public function set_awareness_state ( string $ room , array $ awareness ): bool {
217215 // Awareness is high-frequency, short-lived data (cursor positions, selections)
218216 // that doesn't need cursor-based history. Transients avoid row churn in the table.
219- return set_transient ( 'sync_awareness_ ' . md5 ( $ room ) , $ awareness , MINUTE_IN_SECONDS );
217+ return set_transient ( 'sync_awareness_ ' . $ room , $ awareness , MINUTE_IN_SECONDS );
220218 }
221219}
0 commit comments