@@ -94,6 +94,8 @@ export class TypeSenseService {
9494 type : "string" ,
9595 symbols_to_index : [ "~" ] ,
9696 optional : true ,
97+ sort : true ,
98+ index : true ,
9799 } ,
98100 ] ;
99101
@@ -112,18 +114,37 @@ export class TypeSenseService {
112114
113115 const collection = await this . client . collections ( "players" ) . retrieve ( ) ;
114116
115- const missingFields = fields . filter ( ( field ) => {
116- return ! collection . fields . find ( ( _existingField ) => {
117- return _existingField . name === field . name ;
118- } ) ;
119- } ) ;
117+ const fieldUpdates : Array < Record < string , unknown > > = [ ] ;
118+ let needsRefresh = false ;
119+
120+ for ( const field of fields ) {
121+ const existing = collection . fields . find ( ( f ) => f . name === field . name ) ;
122+
123+ if ( ! existing ) {
124+ fieldUpdates . push ( field ) ;
125+ needsRefresh = true ;
126+ continue ;
127+ }
120128
121- if ( missingFields . length > 0 ) {
129+ const sortChanged = Boolean ( existing . sort ) !== Boolean ( field . sort ) ;
130+ const indexChanged = Boolean ( existing . index ) !== Boolean ( field . index ) ;
131+ const typeChanged = existing . type !== field . type ;
132+
133+ if ( sortChanged || indexChanged || typeChanged ) {
134+ fieldUpdates . push ( { name : field . name , drop : true } ) ;
135+ fieldUpdates . push ( field ) ;
136+ needsRefresh = true ;
137+ }
138+ }
139+
140+ if ( fieldUpdates . length > 0 ) {
122141 await this . client . collections ( "players" ) . update ( {
123- fields : missingFields ,
142+ fields : fieldUpdates as CollectionFieldSchema [ ] ,
124143 } ) ;
125144
126- await this . queue . add ( RefreshAllPlayersJob . name , { } ) ;
145+ if ( needsRefresh ) {
146+ await this . queue . add ( RefreshAllPlayersJob . name , { } ) ;
147+ }
127148 }
128149 }
129150
0 commit comments