TopicsForUser loads user's contact list: p2p and grp topics, except for 'me' & 'fnd' subscriptions. Reads and denormalizes Public value.
(uid t.Uid, keepDeleted bool, opts *t.QueryOpt)
| 1570 | // TopicsForUser loads user's contact list: p2p and grp topics, except for 'me' & 'fnd' subscriptions. |
| 1571 | // Reads and denormalizes Public value. |
| 1572 | func (a *adapter) TopicsForUser(uid t.Uid, keepDeleted bool, opts *t.QueryOpt) ([]t.Subscription, error) { |
| 1573 | // Fetch ALL user's subscriptions, even those which has not been modified recently. |
| 1574 | // We are going to use these subscriptions to fetch topics and users which may have been modified recently. |
| 1575 | q := `SELECT createdat,updatedat,deletedat,topic,delid,recvseqid, |
| 1576 | readseqid,modewant,modegiven,private FROM subscriptions WHERE userid=?` |
| 1577 | args := []any{store.DecodeUid(uid)} |
| 1578 | if !keepDeleted { |
| 1579 | // Filter out deleted rows. |
| 1580 | q += " AND deletedat IS NULL" |
| 1581 | } |
| 1582 | |
| 1583 | limit := 0 |
| 1584 | ims := time.Time{} |
| 1585 | if opts != nil { |
| 1586 | if opts.Topic != "" { |
| 1587 | q += " AND topic=?" |
| 1588 | args = append(args, opts.Topic) |
| 1589 | } |
| 1590 | |
| 1591 | // Apply the limit only when the client does not manage the cache (or cold start). |
| 1592 | // Otherwise have to get all subscriptions and do a manual join with users/topics. |
| 1593 | if opts.IfModifiedSince == nil { |
| 1594 | if opts.Limit > 0 && opts.Limit < a.maxResults { |
| 1595 | limit = opts.Limit |
| 1596 | } else { |
| 1597 | limit = a.maxResults |
| 1598 | } |
| 1599 | } else { |
| 1600 | ims = *opts.IfModifiedSince |
| 1601 | } |
| 1602 | } else { |
| 1603 | limit = a.maxResults |
| 1604 | } |
| 1605 | |
| 1606 | if limit > 0 { |
| 1607 | q += " LIMIT ?" |
| 1608 | args = append(args, limit) |
| 1609 | } |
| 1610 | |
| 1611 | q, args = expandQuery(q, args...) |
| 1612 | |
| 1613 | ctx, cancel := a.getContext() |
| 1614 | if cancel != nil { |
| 1615 | defer cancel() |
| 1616 | } |
| 1617 | rows, err := a.db.Query(ctx, q, args...) |
| 1618 | if err != nil { |
| 1619 | return nil, err |
| 1620 | } |
| 1621 | // Must close rows manually as we will be reusing it. |
| 1622 | |
| 1623 | // Fetch subscriptions. Two queries are needed: users table (p2p) and topics table (grp). |
| 1624 | // Prepare a list of separate subscriptions to users vs topics |
| 1625 | join := make(map[string]t.Subscription) // Keeping these to make a join with table for .private and .access |
| 1626 | topq := make([]any, 0, 16) |
| 1627 | usrq := make([]any, 0, 16) |
| 1628 | for rows.Next() { |
| 1629 | var sub t.Subscription |
nothing calls this directly
no test coverage detected