fix(typesense): make sure searching works when no task has a comment at index time

This commit is contained in:
kolaente 2023-09-29 16:35:59 +02:00
parent 70d1903dca
commit 8f4ee3a089
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 81 additions and 0 deletions

View File

@ -226,6 +226,11 @@ func ReindexAllTasks() (err error) {
return fmt.Errorf("could not get all tasks: %s", err.Error())
}
err = indexDummyTask()
if err != nil {
return fmt.Errorf("could not index dummy task: %w", err)
}
err = reindexTasks(s, tasks)
if err != nil {
return fmt.Errorf("could not reindex all tasks: %s", err.Error())
@ -292,6 +297,82 @@ func reindexTasks(s *xorm.Session, tasks map[int64]*Task) (err error) {
return nil
}
func indexDummyTask() (err error) {
// The initial sync should contain one dummy task with all related fields populated so that typesense
// creates the indexes properly. A little hacky, but gets the job done.
dummyTask := &typesenseTask{
ID: "-100",
Title: "Dummytask",
Created: time.Now().Unix(),
Updated: time.Now().Unix(),
Reminders: []*TaskReminder{
{
ID: -10,
TaskID: -100,
Reminder: time.Now(),
RelativePeriod: 10,
RelativeTo: ReminderRelationDueDate,
Created: time.Now(),
},
},
Assignees: []*user.User{
{
ID: -100,
Username: "dummy",
Name: "dummy",
Email: "dummy@vikunja",
Created: time.Now(),
Updated: time.Now(),
},
},
Labels: []*Label{
{
ID: -110,
Title: "dummylabel",
Description: "Lorem Ipsum Dummy",
HexColor: "000000",
Created: time.Now(),
Updated: time.Now(),
},
},
Attachments: []*TaskAttachment{
{
ID: -120,
TaskID: -100,
Created: time.Now(),
},
},
Comments: []*TaskComment{
{
ID: -220,
Comment: "Lorem Ipsum Dummy",
Created: time.Now(),
Updated: time.Now(),
Author: &user.User{
ID: -100,
Username: "dummy",
Name: "dummy",
Email: "dummy@vikunja",
Created: time.Now(),
Updated: time.Now(),
},
},
},
}
_, err = typesenseClient.Collection("tasks").
Documents().
Create(dummyTask)
if err != nil {
return
}
_, err = typesenseClient.Collection("tasks").
Document(dummyTask.ID).
Delete()
return
}
type typesenseTask struct {
ID string `json:"id"`
Title string `json:"title"`