carddav: paging support

This commit is contained in:
emersion 2017-09-04 11:46:14 +02:00
parent 38e625fbe2
commit e3ec66ed0f
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
1 changed files with 21 additions and 11 deletions

View File

@ -64,19 +64,29 @@ func (ab *addressBook) ListAddressObjects() ([]carddav.AddressObject, error) {
return aos, nil return aos, nil
} }
// TODO: paging support var aos []carddav.AddressObject
total, contacts, err := ab.c.ListContactsExport(0, 0) page := 0
if err != nil { for {
return nil, err total, contacts, err := ab.c.ListContactsExport(page, 0)
} if err != nil {
return nil, err
}
ab.total = total
ab.total = total if aos == nil {
aos = make([]carddav.AddressObject, 0, total)
}
aos := make([]carddav.AddressObject, len(contacts)) for _, contact := range contacts {
for i, contact := range contacts { ao := &addressObject{c: ab.c, contact: contact}
ao := &addressObject{c: ab.c, contact: contact} ab.cache[contact.ID] = ao
ab.cache[contact.ID] = ao aos = append(aos, ao)
aos[i] = ao }
if len(aos) == total || len(contacts) == 0 {
break
}
page++
} }
return aos, nil return aos, nil