sonu sharma
06/12/2021, 7:01 AMKishore Nallan
06/12/2021, 7:14 AMupdated_at
and is_deleted
2. When a record is deleted the is_deleted
is set to true
and the updated_at
also should be updated.
3. When a record is updated, similarly, the updated_at
field should also be updated.
4. When the Typesense sync cron job runs, it will query for the records that need to be synced with this query: SELECT * FROM table WHERE updated_at < NOW() AND id > $prev_id ORDER BY updated_at ASC, id ASC
5. The $prev_id
value is the largest record ID processed in every cron -- this should be stored after every cron and is referenced for the next cron.
6. We use updated_at < NOW()
to prevent picking up records currently being written to.
7. To prune your database of deleted records, you can run another weekly cron that just deletes all the records which have the is_deleted
flag set but is older than a few days old (to prevent interfering with Typesense cron which runs more often)Kishore Nallan
06/12/2021, 7:19 AMis_deleted
flag to decide whether you should be deleting the record from Typesense or updating Typesense. The update and delete batch operations must be separated since upserts and deletes cannot be batched together in the same API call.Kishore Nallan
06/12/2021, 7:20 AMsonu sharma
06/13/2021, 4:27 PM