carddav: paging support
This commit is contained in:
parent
38e625fbe2
commit
e3ec66ed0f
|
@ -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
|
||||||
|
for {
|
||||||
|
total, contacts, err := ab.c.ListContactsExport(page, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ab.total = total
|
ab.total = total
|
||||||
|
|
||||||
aos := make([]carddav.AddressObject, len(contacts))
|
if aos == nil {
|
||||||
for i, contact := range contacts {
|
aos = make([]carddav.AddressObject, 0, total)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, 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[i] = ao
|
aos = append(aos, ao)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(aos) == total || len(contacts) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
page++
|
||||||
}
|
}
|
||||||
|
|
||||||
return aos, nil
|
return aos, nil
|
||||||
|
|
Loading…
Reference in New Issue