1
0

fix(typesense): update tasks in Typesense directly when the change happened

Resolves https://community.vikunja.io/t/no-filters-working-assignee-date-task-done-etc/1910
This commit is contained in:
kolaente
2024-01-28 11:46:52 +01:00
parent ae9b382963
commit 90ad975ca0
4 changed files with 68 additions and 26 deletions

View File

@ -26,6 +26,7 @@ import (
func init() {
rootCmd.AddCommand(indexCmd)
rootCmd.AddCommand(partialReindexCmd)
}
var indexCmd = &cobra.Command{
@ -35,8 +36,8 @@ var indexCmd = &cobra.Command{
initialize.FullInitWithoutAsync()
},
Run: func(cmd *cobra.Command, args []string) {
if !config.TypesenseEnabled.GetBool() {
log.Error("Typesense not enabled")
if config.TypesenseURL.GetString() == "" {
log.Error("Typesense not configured")
return
}
@ -56,3 +57,32 @@ var indexCmd = &cobra.Command{
log.Infof("Done!")
},
}
var partialReindexCmd = &cobra.Command{
Use: "partial-index",
Short: "Reindex any tasks which were not indexed yet into Typesense. This will not remove any existing index.",
PreRun: func(cmd *cobra.Command, args []string) {
initialize.FullInitWithoutAsync()
},
Run: func(cmd *cobra.Command, args []string) {
if config.TypesenseURL.GetString() == "" {
log.Error("Typesense not configured")
return
}
log.Infof("Indexing… This may take a while.")
err := models.CreateTypesenseCollections()
if err != nil {
log.Criticalf("Could not create Typesense collections: %s", err.Error())
return
}
err = models.SyncUpdatedTasksIntoTypesense()
if err != nil {
log.Criticalf("Could not reindex all changed tasks into Typesense: %s", err.Error())
return
}
log.Infof("Done!")
},
}