some database code cleanups

This commit is contained in:
2026-03-05 15:47:23 -07:00
parent 1f450dcf14
commit 55c5c88c95
13 changed files with 137 additions and 137 deletions
+4 -4
View File
@@ -64,13 +64,13 @@ func AmGetAd(ctx context.Context, adid int32) (*Advert, error) {
if ok { if ok {
return rc.(*Advert), nil return rc.(*Advert), nil
} }
var theAd Advert theAd := new(Advert)
err := amdb.GetContext(ctx, &theAd, "SELECT * FROM adverts WHERE adid = ?", adid) err := amdb.GetContext(ctx, theAd, "SELECT * FROM adverts WHERE adid = ?", adid)
if err != nil { if err != nil {
return nil, err return nil, err
} }
adCache.Add(adid, &theAd) adCache.Add(adid, theAd)
return &theAd, nil return theAd, nil
} }
// AmGetRandomAd gets a random ad from the // AmGetRandomAd gets a random ad from the
+6 -6
View File
@@ -174,8 +174,8 @@ func (ar *AuditRecord) Store(ctx context.Context) error {
* Returns: * Returns:
* The audit record pointer. * The audit record pointer.
*/ */
func AmNewAudit(rectype int32, uid int32, ip string, data ...string) *AuditRecord { func AmNewAudit(rectype, uid int32, ip string, data ...string) *AuditRecord {
rc := AuditRecord{Event: rectype, Uid: uid, CommId: 0} rc := &AuditRecord{Event: rectype, Uid: uid, CommId: 0}
if len(ip) > 0 { if len(ip) > 0 {
rc.IP = &ip rc.IP = &ip
} }
@@ -194,7 +194,7 @@ func AmNewAudit(rectype int32, uid int32, ip string, data ...string) *AuditRecor
rc.Data4 = &(data[3]) rc.Data4 = &(data[3])
} }
} }
return &rc return rc
} }
/* AmNewCommAudit creates a new audit record tied to a community. /* AmNewCommAudit creates a new audit record tied to a community.
@@ -207,8 +207,8 @@ func AmNewAudit(rectype int32, uid int32, ip string, data ...string) *AuditRecor
* Returns: * Returns:
* The audit record pointer. * The audit record pointer.
*/ */
func AmNewCommAudit(rectype int32, uid int32, commid int32, ip string, data ...string) *AuditRecord { func AmNewCommAudit(rectype, uid, commid int32, ip string, data ...string) *AuditRecord {
rc := AuditRecord{Event: rectype, Uid: uid, CommId: commid} rc := &AuditRecord{Event: rectype, Uid: uid, CommId: commid}
if len(ip) > 0 { if len(ip) > 0 {
rc.IP = &ip rc.IP = &ip
} }
@@ -227,7 +227,7 @@ func AmNewCommAudit(rectype int32, uid int32, commid int32, ip string, data ...s
rc.Data4 = &(data[3]) rc.Data4 = &(data[3])
} }
} }
return &rc return rc
} }
// AmStoreAudit stores the audit record in the background. // AmStoreAudit stores the audit record in the background.
+41 -41
View File
@@ -127,7 +127,7 @@ var memberCache *lru.Cache = nil
var memberMutex sync.Mutex var memberMutex sync.Mutex
// stuffMembership stuffs a membership record into the cache. // stuffMembership stuffs a membership record into the cache.
func stuffMembership(cid int32, uid int32, member bool, locked bool, level uint16) { func stuffMembership(cid int32, uid int32, member, locked bool, level uint16) {
key := fmt.Sprintf("%d:%d", cid, uid) key := fmt.Sprintf("%d:%d", cid, uid)
memberMutex.Lock() memberMutex.Lock()
memberCache.Add(key, &memberCacheData{isMember: member, locked: locked, level: level}) memberCache.Add(key, &memberCacheData{isMember: member, locked: locked, level: level})
@@ -253,13 +253,13 @@ func (c *Community) MemberCount(ctx context.Context, hidden bool) (int, error) {
* ListMembersOperRegex - The specified field matches the regular expression in "term". * ListMembersOperRegex - The specified field matches the regular expression in "term".
* term - The search term, as specified above. * term - The search term, as specified above.
* offset - Number of members to skip at beginning of list. * offset - Number of members to skip at beginning of list.
* max - Maximum number of members to return. * maxCount - Maximum number of members to return.
* Returns: * Returns:
* Array of User pointers representing the return elements. * Array of User pointers representing the return elements.
* The total number of members matching this query (could be greater than max) * The total number of members matching this query (could be greater than max)
* Standard Go error status. * Standard Go error status.
*/ */
func (c *Community) ListMembers(ctx context.Context, field int, oper int, term string, offset int, max int, showHidden bool) ([]*User, int, error) { func (c *Community) ListMembers(ctx context.Context, field, oper int, term string, offset, maxCount int, showHidden bool) ([]*User, int, error) {
var query strings.Builder var query strings.Builder
if field != ListMembersFieldNone && oper != ListMembersOperNone { if field != ListMembersFieldNone && oper != ListMembersOperNone {
query.WriteString(" AND ") query.WriteString(" AND ")
@@ -303,16 +303,16 @@ func (c *Community) ListMembers(ctx context.Context, field int, oper int, term s
AND u.contactid = c.contactid`+q, c.Id); err == nil { AND u.contactid = c.contactid`+q, c.Id); err == nil {
if offset > 0 { if offset > 0 {
rs, err = amdb.QueryContext(ctx, `SELECT m.uid FROM commmember m, users u, contacts c WHERE m.commid = ? AND m.uid = u.uid rs, err = amdb.QueryContext(ctx, `SELECT m.uid FROM commmember m, users u, contacts c WHERE m.commid = ? AND m.uid = u.uid
AND u.contactid = c.contactid`+q+" ORDER BY u.username LIMIT ? OFFSET ?", c.Id, max, offset) AND u.contactid = c.contactid`+q+" ORDER BY u.username LIMIT ? OFFSET ?", c.Id, maxCount, offset)
} else { } else {
rs, err = amdb.QueryContext(ctx, `SELECT m.uid FROM commmember m, users u, contacts c WHERE m.commid = ? AND m.uid = u.uid rs, err = amdb.QueryContext(ctx, `SELECT m.uid FROM commmember m, users u, contacts c WHERE m.commid = ? AND m.uid = u.uid
AND u.contactid = c.contactid`+q+" ORDER BY u.username LIMIT ?", c.Id, max) AND u.contactid = c.contactid`+q+" ORDER BY u.username LIMIT ?", c.Id, maxCount)
} }
} }
if err != nil { if err != nil {
return nil, total, err return nil, total, err
} }
rc := make([]*User, 0, min(max, 10000)) rc := make([]*User, 0, min(maxCount, 10000))
for rs.Next() { for rs.Next() {
var uid int32 var uid int32
if err = rs.Scan(&uid); err == nil { if err = rs.Scan(&uid); err == nil {
@@ -650,12 +650,12 @@ func AmGetCommunity(ctx context.Context, id int32) (*Community, error) {
if rc, ok := communityCache.Get(id); ok { if rc, ok := communityCache.Get(id); ok {
return rc.(*Community), nil return rc.(*Community), nil
} }
var newcomm Community newcomm := new(Community)
err := amdb.GetContext(ctx, &newcomm, "SELECT * from communities WHERE commid = ?", id) err := amdb.GetContext(ctx, newcomm, "SELECT * from communities WHERE commid = ?", id)
switch err { switch err {
case nil: case nil:
communityCache.Add(id, &newcomm) communityCache.Add(id, newcomm)
return &newcomm, nil return newcomm, nil
case sql.ErrNoRows: case sql.ErrNoRows:
return nil, ErrNoCommunity return nil, ErrNoCommunity
} }
@@ -677,12 +677,12 @@ func AmGetCommunityTx(ctx context.Context, tx *sqlx.Tx, id int32) (*Community, e
if rc, ok := communityCache.Get(id); ok { if rc, ok := communityCache.Get(id); ok {
return rc.(*Community), nil return rc.(*Community), nil
} }
var newcomm Community newcomm := new(Community)
err := tx.GetContext(ctx, &newcomm, "SELECT * from communities WHERE commid = ?", id) err := tx.GetContext(ctx, newcomm, "SELECT * from communities WHERE commid = ?", id)
switch err { switch err {
case nil: case nil:
communityCache.Add(id, &newcomm) communityCache.Add(id, newcomm)
return &newcomm, nil return newcomm, nil
case sql.ErrNoRows: case sql.ErrNoRows:
return nil, ErrNoCommunity return nil, ErrNoCommunity
} }
@@ -791,7 +791,7 @@ func AmGetCommunitiesForUser(ctx context.Context, uid int32) ([]*Community, erro
* Access level within the community, or 0 if the user is not a member. * Access level within the community, or 0 if the user is not a member.
* Standard Go error status. * Standard Go error status.
*/ */
func AmGetCommunityAccessLevel(ctx context.Context, uid int32, commid int32) (uint16, error) { func AmGetCommunityAccessLevel(ctx context.Context, uid, commid int32) (uint16, error) {
var rc uint16 = 0 var rc uint16 = 0
rows, err := amdb.QueryxContext(ctx, `SELECT GREATEST(m.granted_lvl, u.base_lvl) AS level FROM users u, commmember m rows, err := amdb.QueryxContext(ctx, `SELECT GREATEST(m.granted_lvl, u.base_lvl) AS level FROM users u, commmember m
WHERE u.uid = m.uid AND m.uid = ? AND m.commid = ?`, uid, commid) WHERE u.uid = m.uid AND m.uid = ? AND m.commid = ?`, uid, commid)
@@ -844,19 +844,19 @@ func AmAutoJoinCommunities(ctx context.Context, user *User) error {
} }
// internalGetCommProp is a helper used by the community property functions. // internalGetCommProp is a helper used by the community property functions.
func internalGetCommProp(ctx context.Context, cid int32, ndx int32) (*CommunityProperties, error) { func internalGetCommProp(ctx context.Context, cid, ndx int32) (*CommunityProperties, error) {
key := fmt.Sprintf("%d:%d", cid, ndx) key := fmt.Sprintf("%d:%d", cid, ndx)
getCommunityPropMutex.Lock() getCommunityPropMutex.Lock()
defer getCommunityPropMutex.Unlock() defer getCommunityPropMutex.Unlock()
if rc, ok := communityPropCache.Get(key); ok { if rc, ok := communityPropCache.Get(key); ok {
return rc.(*CommunityProperties), nil return rc.(*CommunityProperties), nil
} }
var prop CommunityProperties prop := new(CommunityProperties)
err := amdb.GetContext(ctx, &prop, "SELECT * from propcomm WHERE cid = ? AND ndx = ?", cid, ndx) err := amdb.GetContext(ctx, prop, "SELECT * from propcomm WHERE cid = ? AND ndx = ?", cid, ndx)
switch err { switch err {
case nil: case nil:
communityPropCache.Add(key, &prop) communityPropCache.Add(key, prop)
return &prop, nil return prop, nil
case sql.ErrNoRows: case sql.ErrNoRows:
return nil, nil return nil, nil
} }
@@ -872,7 +872,7 @@ func internalGetCommProp(ctx context.Context, cid int32, ndx int32) (*CommunityP
* Value of the property string. * Value of the property string.
* Standard Go error status. * Standard Go error status.
*/ */
func AmGetCommunityProperty(ctx context.Context, cid int32, ndx int32) (*string, error) { func AmGetCommunityProperty(ctx context.Context, cid, ndx int32) (*string, error) {
p, err := internalGetCommProp(ctx, cid, ndx) p, err := internalGetCommProp(ctx, cid, ndx)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -891,7 +891,7 @@ func AmGetCommunityProperty(ctx context.Context, cid int32, ndx int32) (*string,
* Returns: * Returns:
* Standard Go error status. * Standard Go error status.
*/ */
func AmSetCommunityProperty(ctx context.Context, cid int32, ndx int32, val *string) error { func AmSetCommunityProperty(ctx context.Context, cid, ndx int32, val *string) error {
p, err := internalGetCommProp(ctx, cid, ndx) p, err := internalGetCommProp(ctx, cid, ndx)
if err != nil { if err != nil {
return err return err
@@ -930,8 +930,8 @@ func AmSetCommunityProperty(ctx context.Context, cid int32, ndx int32, val *stri
* Pointer to new Community record, or nil. * Pointer to new Community record, or nil.
* Standard Go error status. * Standard Go error status.
*/ */
func AmCreateCommunity(ctx context.Context, name string, alias string, hostUid int32, language *string, synopsis *string, func AmCreateCommunity(ctx context.Context, name, alias string, hostUid int32, language, synopsis, rules, joinkey *string,
rules *string, joinkey *string, hideDirectory bool, hideSearch bool, remoteIP string) (*Community, error) { hideDirectory, hideSearch bool, remoteIP string) (*Community, error) {
tx, commit, rollback := transaction(ctx) tx, commit, rollback := transaction(ctx)
defer rollback() defer rollback()
@@ -1012,14 +1012,14 @@ func AmCreateCommunity(ctx context.Context, name string, alias string, hostUid i
* ctx - Standard Go context value. * ctx - Standard Go context value.
* catid - Category ID to search for. * catid - Category ID to search for.
* offset - Number of communities to skip at beginning of list. * offset - Number of communities to skip at beginning of list.
* max - Maximum number of communities to return. * maxCount - Maximum number of communities to return.
* showAll - Include communities that are "hidden in directory." * showAll - Include communities that are "hidden in directory."
* Returns: * Returns:
* Array of Community pointers representing the return elements. * Array of Community pointers representing the return elements.
* The total number of communities matching this query (could be greater than max) * The total number of communities matching this query (could be greater than max)
* Standard Go error status. * Standard Go error status.
*/ */
func AmGetCommunitiesForCategory(ctx context.Context, catid int32, offset int, max int, showAll bool) ([]*Community, int, error) { func AmGetCommunitiesForCategory(ctx context.Context, catid int32, offset, maxCount int, showAll bool) ([]*Community, int, error) {
var err error var err error
var total int var total int
if showAll { if showAll {
@@ -1034,22 +1034,22 @@ func AmGetCommunitiesForCategory(ctx context.Context, catid int32, offset int, m
if showAll { if showAll {
if offset > 0 { if offset > 0 {
rs, err = amdb.QueryContext(ctx, "SELECT commid FROM communities WHERE catid = ? ORDER BY commname LIMIT ? OFFSET ?", rs, err = amdb.QueryContext(ctx, "SELECT commid FROM communities WHERE catid = ? ORDER BY commname LIMIT ? OFFSET ?",
catid, max, offset) catid, maxCount, offset)
} else { } else {
rs, err = amdb.QueryContext(ctx, "SELECT commid FROM communities WHERE catid = ? ORDER BY commname LIMIT ?", catid, max) rs, err = amdb.QueryContext(ctx, "SELECT commid FROM communities WHERE catid = ? ORDER BY commname LIMIT ?", catid, maxCount)
} }
} else { } else {
if offset > 0 { if offset > 0 {
rs, err = amdb.QueryContext(ctx, "SELECT commid FROM communities WHERE catid = ? AND hide_dir = 0 ORDER BY commname LIMIT ? OFFSET ?", rs, err = amdb.QueryContext(ctx, "SELECT commid FROM communities WHERE catid = ? AND hide_dir = 0 ORDER BY commname LIMIT ? OFFSET ?",
catid, max, offset) catid, maxCount, offset)
} else { } else {
rs, err = amdb.QueryContext(ctx, "SELECT commid FROM communities WHERE catid = ? AND hide_dir = 0 ORDER BY commname LIMIT ?", catid, max) rs, err = amdb.QueryContext(ctx, "SELECT commid FROM communities WHERE catid = ? AND hide_dir = 0 ORDER BY commname LIMIT ?", catid, maxCount)
} }
} }
if err != nil { if err != nil {
return nil, total, err return nil, total, err
} }
rc := make([]*Community, 0, min(max, 10000)) rc := make([]*Community, 0, min(maxCount, 10000))
for rs.Next() { for rs.Next() {
var commid int32 var commid int32
if err = rs.Scan(&commid); err == nil { if err = rs.Scan(&commid); err == nil {
@@ -1074,14 +1074,14 @@ func AmGetCommunitiesForCategory(ctx context.Context, catid int32, offset int, m
* SearchCommOperRegex - The specified field matches the regular expression in "term". * SearchCommOperRegex - The specified field matches the regular expression in "term".
* term - The search term, as specified above. * term - The search term, as specified above.
* offset - Number of communities to skip at beginning of list. * offset - Number of communities to skip at beginning of list.
* max - Maximum number of communities to return. * maxCount - Maximum number of communities to return.
* showAll - Include communities that are "hidden in search." * showAll - Include communities that are "hidden in search."
* Returns: * Returns:
* Array of Community pointers representing the return elements. * Array of Community pointers representing the return elements.
* The total number of communities matching this query (could be greater than max) * The total number of communities matching this query (could be greater than max)
* Standard Go error status. * Standard Go error status.
*/ */
func AmSearchCommunities(ctx context.Context, field int, oper int, term string, offset int, max int, showAll bool) ([]*Community, int, error) { func AmSearchCommunities(ctx context.Context, field, oper int, term string, offset, maxCount int, showAll bool) ([]*Community, int, error) {
var queryPortion strings.Builder var queryPortion strings.Builder
queryPortion.WriteString("WHERE ") queryPortion.WriteString("WHERE ")
switch field { switch field {
@@ -1119,14 +1119,14 @@ func AmSearchCommunities(ctx context.Context, field int, oper int, term string,
} }
var rs *sql.Rows var rs *sql.Rows
if offset > 0 { if offset > 0 {
rs, err = amdb.QueryContext(ctx, "SELECT commid FROM communities "+q+" ORDER BY commname LIMIT ? OFFSET ?", max, offset) rs, err = amdb.QueryContext(ctx, "SELECT commid FROM communities "+q+" ORDER BY commname LIMIT ? OFFSET ?", maxCount, offset)
} else { } else {
rs, err = amdb.QueryContext(ctx, "SELECT commid FROM communities "+q+" ORDER BY commname LIMIT ?", max) rs, err = amdb.QueryContext(ctx, "SELECT commid FROM communities "+q+" ORDER BY commname LIMIT ?", maxCount)
} }
if err != nil { if err != nil {
return nil, total, err return nil, total, err
} }
rc := make([]*Community, 0, min(max, 10000)) rc := make([]*Community, 0, min(maxCount, 10000))
for rs.Next() { for rs.Next() {
var commid int32 var commid int32
if err = rs.Scan(&commid); err == nil { if err = rs.Scan(&commid); err == nil {
@@ -1154,13 +1154,13 @@ func AmSearchCommunities(ctx context.Context, field int, oper int, term string,
* SearchUserOperRegex - The specified field matches the regular expression in "term". * SearchUserOperRegex - The specified field matches the regular expression in "term".
* term - The search term, as specified above. * term - The search term, as specified above.
* offset - Number of users to skip at beginning of list. * offset - Number of users to skip at beginning of list.
* max - Maximum number of users to return. * maxCount - Maximum number of users to return.
* Returns: * Returns:
* Array of User pointers representing the return elements. * Array of User pointers representing the return elements.
* The total number of users matching this query (could be greater than max) * The total number of users matching this query (could be greater than max)
* Standard Go error status. * Standard Go error status.
*/ */
func AmSearchCommunityMembers(ctx context.Context, c *Community, field int, oper int, term string, offset int, max int) ([]*User, int, error) { func AmSearchCommunityMembers(ctx context.Context, c *Community, field, oper int, term string, offset, maxCount int) ([]*User, int, error) {
var queryPortion strings.Builder var queryPortion strings.Builder
switch field { switch field {
case SearchUserFieldName: case SearchUserFieldName:
@@ -1203,15 +1203,15 @@ func AmSearchCommunityMembers(ctx context.Context, c *Community, field int, oper
var rs *sql.Rows var rs *sql.Rows
if offset > 0 { if offset > 0 {
rs, err = amdb.QueryContext(ctx, `SELECT u.uid FROM users u, contacts c, commmember m WHERE u.contactid = c.contactid AND u.uid = m.uid rs, err = amdb.QueryContext(ctx, `SELECT u.uid FROM users u, contacts c, commmember m WHERE u.contactid = c.contactid AND u.uid = m.uid
AND m.commid = ? AND u.is_anon = 0 AND `+q+" ORDER BY u.username LIMIT ? OFFSET ?", c.Id, max, offset) AND m.commid = ? AND u.is_anon = 0 AND `+q+" ORDER BY u.username LIMIT ? OFFSET ?", c.Id, maxCount, offset)
} else { } else {
rs, err = amdb.QueryContext(ctx, `SELECT u.uid FROM users u, contacts c, commmember m WHERE u.contactid = c.contactid AND u.uid = m.uid rs, err = amdb.QueryContext(ctx, `SELECT u.uid FROM users u, contacts c, commmember m WHERE u.contactid = c.contactid AND u.uid = m.uid
AND m.commid = ? AND u.is_anon = 0 AND `+q+" ORDER BY u.username LIMIT ?", c.Id, max) AND m.commid = ? AND u.is_anon = 0 AND `+q+" ORDER BY u.username LIMIT ?", c.Id, maxCount)
} }
if err != nil { if err != nil {
return nil, total, err return nil, total, err
} }
rc := make([]*User, 0, min(max, 10000)) rc := make([]*User, 0, min(maxCount, 10000))
for rs.Next() { for rs.Next() {
var uid int32 var uid int32
if err = rs.Scan(&uid); err == nil { if err = rs.Scan(&uid); err == nil {
+18 -18
View File
@@ -408,14 +408,14 @@ func (c *Conference) SaveFlags(ctx context.Context, f *util.OptionSet) error {
// Settings returns the settings for a user. // Settings returns the settings for a user.
func (c *Conference) Settings(ctx context.Context, u *User) (*ConferenceSettings, error) { func (c *Conference) Settings(ctx context.Context, u *User) (*ConferenceSettings, error) {
var settings ConferenceSettings settings := new(ConferenceSettings)
err := amdb.GetContext(ctx, &settings, "SELECT * FROM confsettings WHERE confid = ? AND uid = ?", c.ConfId, u.Uid) err := amdb.GetContext(ctx, settings, "SELECT * FROM confsettings WHERE confid = ? AND uid = ?", c.ConfId, u.Uid)
switch err { switch err {
case nil: case nil:
settings.newflag = false settings.newflag = false
return &settings, nil return settings, nil
case sql.ErrNoRows: case sql.ErrNoRows:
settings := ConferenceSettings{ settings := &ConferenceSettings{
ConfId: c.ConfId, ConfId: c.ConfId,
Uid: u.Uid, Uid: u.Uid,
DefaultPseud: nil, DefaultPseud: nil,
@@ -423,7 +423,7 @@ func (c *Conference) Settings(ctx context.Context, u *User) (*ConferenceSettings
LastPost: nil, LastPost: nil,
newflag: true, newflag: true,
} }
return &settings, nil return settings, nil
} }
return nil, err return nil, err
} }
@@ -456,8 +456,8 @@ func (c *Conference) SetInfo(ctx context.Context, name, descr string, read_lvl,
hide_lvl = ?, nuke_lvl = ?, change_lvl = ?, delete_lvl = ?, lastupdate = NOW() WHERE confid = ?`, name, descr, read_lvl, post_lvl, hide_lvl = ?, nuke_lvl = ?, change_lvl = ?, delete_lvl = ?, lastupdate = NOW() WHERE confid = ?`, name, descr, read_lvl, post_lvl,
create_lvl, hide_lvl, nuke_lvl, change_lvl, delete_lvl, c.ConfId) create_lvl, hide_lvl, nuke_lvl, change_lvl, delete_lvl, c.ConfId)
if err == nil { if err == nil {
var tmp Conference tmp := new(Conference)
if err = amdb.GetContext(ctx, &tmp, "SELECT * FROM confs WHERE confid = ?", c.ConfId); err == nil { if err = amdb.GetContext(ctx, tmp, "SELECT * FROM confs WHERE confid = ?", c.ConfId); err == nil {
if c.Name != tmp.Name { if c.Name != tmp.Name {
AmStoreAudit(AmNewCommAudit(AuditConferenceName, u.Uid, comm.Id, ipaddr, fmt.Sprintf("confid=%d", c.ConfId), fmt.Sprintf("name='%s'", tmp.Name))) AmStoreAudit(AmNewCommAudit(AuditConferenceName, u.Uid, comm.Id, ipaddr, fmt.Sprintf("confid=%d", c.ConfId), fmt.Sprintf("name='%s'", tmp.Name)))
} }
@@ -1016,12 +1016,12 @@ func AmGetConference(ctx context.Context, id int32) (*Conference, error) {
if rc, ok := conferenceCache.Get(id); ok { if rc, ok := conferenceCache.Get(id); ok {
return rc.(*Conference), nil return rc.(*Conference), nil
} }
var conf Conference conf := new(Conference)
err := amdb.GetContext(ctx, &conf, "SELECT * from confs where confid = ?", id) err := amdb.GetContext(ctx, conf, "SELECT * from confs where confid = ?", id)
switch err { switch err {
case nil: case nil:
conferenceCache.Add(id, &conf) conferenceCache.Add(id, conf)
return &conf, nil return conf, nil
case sql.ErrNoRows: case sql.ErrNoRows:
return nil, ErrNoConference return nil, ErrNoConference
} }
@@ -1137,19 +1137,19 @@ func AmListConferences(ctx context.Context, cid int32, showHidden bool) ([]*Conf
} }
// internalGetConfProp is a helper used by the conference property functions. // internalGetConfProp is a helper used by the conference property functions.
func internalGetConfProp(ctx context.Context, confid int32, ndx int32) (*ConferenceProperties, error) { func internalGetConfProp(ctx context.Context, confid, ndx int32) (*ConferenceProperties, error) {
key := fmt.Sprintf("%d:%d", confid, ndx) key := fmt.Sprintf("%d:%d", confid, ndx)
getConferencePropMutex.Lock() getConferencePropMutex.Lock()
defer getConferencePropMutex.Unlock() defer getConferencePropMutex.Unlock()
if rc, ok := conferencePropCache.Get(key); ok { if rc, ok := conferencePropCache.Get(key); ok {
return rc.(*ConferenceProperties), nil return rc.(*ConferenceProperties), nil
} }
var prop ConferenceProperties prop := new(ConferenceProperties)
err := amdb.GetContext(ctx, &prop, "SELECT * from propconf WHERE confid = ? AND ndx = ?", confid, ndx) err := amdb.GetContext(ctx, prop, "SELECT * from propconf WHERE confid = ? AND ndx = ?", confid, ndx)
switch err { switch err {
case nil: case nil:
conferencePropCache.Add(key, &prop) conferencePropCache.Add(key, prop)
return &prop, nil return prop, nil
case sql.ErrNoRows: case sql.ErrNoRows:
return nil, nil return nil, nil
} }
@@ -1165,7 +1165,7 @@ func internalGetConfProp(ctx context.Context, confid int32, ndx int32) (*Confere
* Value of the property string. * Value of the property string.
* Standard Go error status. * Standard Go error status.
*/ */
func AmGetConferenceProperty(ctx context.Context, confid int32, ndx int32) (*string, error) { func AmGetConferenceProperty(ctx context.Context, confid, ndx int32) (*string, error) {
p, err := internalGetConfProp(ctx, confid, ndx) p, err := internalGetConfProp(ctx, confid, ndx)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -1184,7 +1184,7 @@ func AmGetConferenceProperty(ctx context.Context, confid int32, ndx int32) (*str
* Returns: * Returns:
* Standard Go error status. * Standard Go error status.
*/ */
func AmSetConferenceProperty(ctx context.Context, confid int32, ndx int32, val *string) error { func AmSetConferenceProperty(ctx context.Context, confid, ndx int32, val *string) error {
p, err := internalGetConfProp(ctx, confid, ndx) p, err := internalGetConfProp(ctx, confid, ndx)
if err != nil { if err != nil {
return err return err
+10 -10
View File
@@ -197,7 +197,7 @@ func (ci *ContactInfo) Save(ctx context.Context, changer *User, ipaddr string) (
// Clone makes a copy of the ContactInfo. // Clone makes a copy of the ContactInfo.
func (ci *ContactInfo) Clone() *ContactInfo { func (ci *ContactInfo) Clone() *ContactInfo {
newstr := ContactInfo{ newstr := &ContactInfo{
ContactId: ci.ContactId, ContactId: ci.ContactId,
GivenName: ci.GivenName, GivenName: ci.GivenName,
FamilyName: ci.FamilyName, FamilyName: ci.FamilyName,
@@ -225,7 +225,7 @@ func (ci *ContactInfo) Clone() *ContactInfo {
URL: ci.URL, URL: ci.URL,
LastUpdate: ci.LastUpdate, LastUpdate: ci.LastUpdate,
} }
return &newstr return newstr
} }
// contactCache is the cache for ContactInfo objects. // contactCache is the cache for ContactInfo objects.
@@ -245,11 +245,11 @@ func setupContactsCache() {
// internalContactInfo retrieves the contact info from the database. // internalContactInfo retrieves the contact info from the database.
func internalContactInfo(ctx context.Context, id int32) (*ContactInfo, error) { func internalContactInfo(ctx context.Context, id int32) (*ContactInfo, error) {
var cinf ContactInfo cinf := new(ContactInfo)
if err := amdb.GetContext(ctx, &cinf, "SELECT * from contacts WHERE contactid = ?", id); err != nil { if err := amdb.GetContext(ctx, cinf, "SELECT * from contacts WHERE contactid = ?", id); err != nil {
return nil, err return nil, err
} }
return &cinf, nil return cinf, nil
} }
/* AmGetContactInfo retrieves the contact info for a given identifier. /* AmGetContactInfo retrieves the contact info for a given identifier.
@@ -304,8 +304,8 @@ func AmGetContactInfoForUser(ctx context.Context, uid int32) (*ContactInfo, erro
* New ContactInfo structure. * New ContactInfo structure.
*/ */
func AmNewUserContactInfo(uid int32) *ContactInfo { func AmNewUserContactInfo(uid int32) *ContactInfo {
rc := ContactInfo{OwnerUid: uid, OwnerCommId: -1} rc := &ContactInfo{OwnerUid: uid, OwnerCommId: -1}
return &rc return rc
} }
/* AmNewCommunityContactInfo creates a new contact info record for the community. /* AmNewCommunityContactInfo creates a new contact info record for the community.
@@ -315,7 +315,7 @@ func AmNewUserContactInfo(uid int32) *ContactInfo {
* Returns: * Returns:
* New ContactInfo structure. * New ContactInfo structure.
*/ */
func AmNewCommunityContactInfo(uid int32, cid int32) *ContactInfo { func AmNewCommunityContactInfo(uid, cid int32) *ContactInfo {
rc := ContactInfo{OwnerUid: uid, OwnerCommId: cid} rc := &ContactInfo{OwnerUid: uid, OwnerCommId: cid}
return &rc return rc
} }
+5 -5
View File
@@ -62,7 +62,7 @@ var globalPropMutex sync.Mutex
// Clone clones the entire global state. // Clone clones the entire global state.
func (g *Globals) Clone() *Globals { func (g *Globals) Clone() *Globals {
rc := Globals{ rc := &Globals{
PostsPerPage: g.PostsPerPage, PostsPerPage: g.PostsPerPage,
OldPostsAtTop: g.OldPostsAtTop, OldPostsAtTop: g.OldPostsAtTop,
MaxSearchPage: g.MaxSearchPage, MaxSearchPage: g.MaxSearchPage,
@@ -73,7 +73,7 @@ func (g *Globals) Clone() *Globals {
CommunityCreateLevel: g.CommunityCreateLevel, CommunityCreateLevel: g.CommunityCreateLevel,
flags: nil, flags: nil,
} }
return &rc return rc
} }
// Flags returns the global flags. // Flags returns the global flags.
@@ -107,11 +107,11 @@ func AmGlobals(ctx context.Context) (*Globals, error) {
globalsMutex.Lock() globalsMutex.Lock()
defer globalsMutex.Unlock() defer globalsMutex.Unlock()
if theGlobals == nil { if theGlobals == nil {
var g Globals g := new(Globals)
if err := amdb.GetContext(ctx, &g, "SELECT * FROM globals"); err != nil { if err := amdb.GetContext(ctx, g, "SELECT * FROM globals"); err != nil {
return nil, err return nil, err
} }
theGlobals = &g theGlobals = g
} }
return theGlobals, nil return theGlobals, nil
} }
+3 -3
View File
@@ -60,11 +60,11 @@ func (img *ImageStore) Save(ctx context.Context) error {
* Standard Go error status. * Standard Go error status.
*/ */
func AmLoadImage(ctx context.Context, id int32) (*ImageStore, error) { func AmLoadImage(ctx context.Context, id int32) (*ImageStore, error) {
var imgdata ImageStore imgdata := new(ImageStore)
if err := amdb.GetContext(ctx, &imgdata, "SELECT * FROM imagestore WHERE imgid = ?", id); err != nil { if err := amdb.GetContext(ctx, imgdata, "SELECT * FROM imagestore WHERE imgid = ?", id); err != nil {
return nil, err return nil, err
} }
return &imgdata, nil return imgdata, nil
} }
/* AmStoreImage stores an image in the database, overwriting one with the same type code and owner if it exists. /* AmStoreImage stores an image in the database, overwriting one with the same type code and owner if it exists.
+3 -3
View File
@@ -272,11 +272,11 @@ func AmListIPBans(ctx context.Context) ([]IPBanEntry, error) {
// AmGetIPBan returns a single IP address ban structure. // AmGetIPBan returns a single IP address ban structure.
func AmGetIPBan(ctx context.Context, id int32) (*IPBanEntry, error) { func AmGetIPBan(ctx context.Context, id int32) (*IPBanEntry, error) {
var ban IPBanEntry ban := new(IPBanEntry)
if err := amdb.GetContext(ctx, &ban, "SELECT * FROM ipban WHERE id = ?", id); err != nil { if err := amdb.GetContext(ctx, ban, "SELECT * FROM ipban WHERE id = ?", id); err != nil {
return nil, err return nil, err
} }
return &ban, nil return ban, nil
} }
// AmAddIPBan adds a new IP address ban. // AmAddIPBan adds a new IP address ban.
+1 -1
View File
@@ -35,7 +35,7 @@ var passwordRequests map[int32]*PasswordChangeRequest = make(map[int32]*Password
* Returns: * Returns:
* Pointer to the new PasswordChangeRequest. * Pointer to the new PasswordChangeRequest.
*/ */
func AmNewPasswordChangeRequest(uid int32, username string, email string) *PasswordChangeRequest { func AmNewPasswordChangeRequest(uid int32, username, email string) *PasswordChangeRequest {
rc := PasswordChangeRequest{Uid: uid, Username: username, Email: email, rc := PasswordChangeRequest{Uid: uid, Username: username, Email: email,
Authentication: util.GenerateRandomConfirmationNumber(), Expires: time.Now().Add(time.Hour)} Authentication: util.GenerateRandomConfirmationNumber(), Expires: time.Now().Add(time.Hour)}
passwordRequests[uid] = &rc passwordRequests[uid] = &rc
+7 -7
View File
@@ -88,11 +88,11 @@ func (p *PostHeader) AttachmentInfo(ctx context.Context) (*PostAttachInfo, error
return nil, errors.New("no attachment data for scribbled post") return nil, errors.New("no attachment data for scribbled post")
} }
row := amdb.QueryRowContext(ctx, "SELECT filename, mimetype, datalen FROM postattach WHERE postid = ?", p.PostId) row := amdb.QueryRowContext(ctx, "SELECT filename, mimetype, datalen FROM postattach WHERE postid = ?", p.PostId)
var rc PostAttachInfo rc := new(PostAttachInfo)
err := row.Scan(&(rc.Filename), &(rc.MIMEType), &(rc.Length)) err := row.Scan(&(rc.Filename), &(rc.MIMEType), &(rc.Length))
switch err { switch err {
case nil: case nil:
return &rc, nil return rc, nil
case sql.ErrNoRows: case sql.ErrNoRows:
return nil, nil return nil, nil
} }
@@ -235,8 +235,8 @@ func (p *PostHeader) PruneAttachment(ctx context.Context, u *User, comm *Communi
// Text returns the text associated with a post. // Text returns the text associated with a post.
func (p *PostHeader) Text(ctx context.Context) (string, error) { func (p *PostHeader) Text(ctx context.Context) (string, error) {
var pd PostData pd := new(PostData)
err := amdb.GetContext(ctx, &pd, "SELECT * FROM postdata WHERE postid = ?", p.PostId) err := amdb.GetContext(ctx, pd, "SELECT * FROM postdata WHERE postid = ?", p.PostId)
switch err { switch err {
case nil: case nil:
if pd.Data == nil { if pd.Data == nil {
@@ -519,11 +519,11 @@ func (p *PostHeader) ImportFix(ctx context.Context, parent int64, dateStamp time
* Standard Go error status. * Standard Go error status.
*/ */
func AmGetPost(ctx context.Context, postId int64) (*PostHeader, error) { func AmGetPost(ctx context.Context, postId int64) (*PostHeader, error) {
var pd PostHeader pd := new(PostHeader)
if err := amdb.GetContext(ctx, &pd, "SELECT * FROM posts WHERE postid = ?", postId); err != nil { if err := amdb.GetContext(ctx, pd, "SELECT * FROM posts WHERE postid = ?", postId); err != nil {
return nil, err return nil, err
} }
return &pd, nil return pd, nil
} }
/* AmGetPostRange gets a range of posts from a topic by post numbers. /* AmGetPostRange gets a range of posts from a topic by post numbers.
+3 -3
View File
@@ -65,7 +65,7 @@ func AmGetSideboxes(ctx context.Context, uid int32) ([]*Sidebox, error) {
} }
// AmReorderSideboxes changes the position of two sideboxes on the user's list. // AmReorderSideboxes changes the position of two sideboxes on the user's list.
func AmReorderSideboxes(ctx context.Context, uid int32, seq1, seq2 int32) error { func AmReorderSideboxes(ctx context.Context, uid, seq1, seq2 int32) error {
tx, commit, rollback := transaction(ctx) tx, commit, rollback := transaction(ctx)
defer rollback() defer rollback()
@@ -86,7 +86,7 @@ func AmReorderSideboxes(ctx context.Context, uid int32, seq1, seq2 int32) error
} }
// AmRemoveSidebox removes a sidebox from the user configuration. // AmRemoveSidebox removes a sidebox from the user configuration.
func AmRemoveSidebox(ctx context.Context, uid int32, boxid int32) error { func AmRemoveSidebox(ctx context.Context, uid, boxid int32) error {
tx, commit, rollback := transaction(ctx) tx, commit, rollback := transaction(ctx)
defer rollback() defer rollback()
@@ -113,7 +113,7 @@ func AmRemoveSidebox(ctx context.Context, uid int32, boxid int32) error {
} }
// AmAppendSidebox appends a new sidebox to the existing user's configuration. // AmAppendSidebox appends a new sidebox to the existing user's configuration.
func AmAppendSidebox(ctx context.Context, uid int32, boxid int32, param *string) error { func AmAppendSidebox(ctx context.Context, uid, boxid int32, param *string) error {
tx, commit, rollback := transaction(ctx) tx, commit, rollback := transaction(ctx)
defer rollback() defer rollback()
+14 -14
View File
@@ -488,14 +488,14 @@ type TopicSummary struct {
* Standard Go error status. * Standard Go error status.
*/ */
func AmGetTopic(ctx context.Context, topicId int32) (*Topic, error) { func AmGetTopic(ctx context.Context, topicId int32) (*Topic, error) {
var top Topic top := new(Topic)
if err := amdb.GetContext(ctx, &top, "SELECT * FROM topics WHERE topicid = ?", topicId); err != nil { if err := amdb.GetContext(ctx, top, "SELECT * FROM topics WHERE topicid = ?", topicId); err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
err = ErrNoTopic err = ErrNoTopic
} }
return nil, err return nil, err
} }
return &top, nil return top, nil
} }
/* AmGetTopicTx retrieves a topic by ID, in a transaction. /* AmGetTopicTx retrieves a topic by ID, in a transaction.
@@ -508,14 +508,14 @@ func AmGetTopic(ctx context.Context, topicId int32) (*Topic, error) {
* Standard Go error status. * Standard Go error status.
*/ */
func AmGetTopicTx(ctx context.Context, tx *sqlx.Tx, topicId int32) (*Topic, error) { func AmGetTopicTx(ctx context.Context, tx *sqlx.Tx, topicId int32) (*Topic, error) {
var top Topic top := new(Topic)
if err := tx.GetContext(ctx, &top, "SELECT * FROM topics WHERE topicid = ?", topicId); err != nil { if err := tx.GetContext(ctx, top, "SELECT * FROM topics WHERE topicid = ?", topicId); err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
err = ErrNoTopic err = ErrNoTopic
} }
return nil, err return nil, err
} }
return &top, nil return top, nil
} }
/* AmGetTopicByNumber retrieves a topic by conference and sequence number. /* AmGetTopicByNumber retrieves a topic by conference and sequence number.
@@ -528,10 +528,10 @@ func AmGetTopicTx(ctx context.Context, tx *sqlx.Tx, topicId int32) (*Topic, erro
* Standard Go error status. * Standard Go error status.
*/ */
func AmGetTopicByNumber(ctx context.Context, conf *Conference, topicNum int16) (*Topic, error) { func AmGetTopicByNumber(ctx context.Context, conf *Conference, topicNum int16) (*Topic, error) {
var top Topic top := new(Topic)
err := amdb.GetContext(ctx, &top, "SELECT * FROM topics WHERE confid = ? AND num = ?", conf.ConfId, topicNum) err := amdb.GetContext(ctx, top, "SELECT * FROM topics WHERE confid = ? AND num = ?", conf.ConfId, topicNum)
if err == nil { if err == nil {
return &top, nil return top, nil
} }
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
err = ErrNoTopic err = ErrNoTopic
@@ -549,10 +549,10 @@ func AmGetTopicByNumber(ctx context.Context, conf *Conference, topicNum int16) (
* Standard Go error status. * Standard Go error status.
*/ */
func AmGetTopicByName(ctx context.Context, conf *Conference, name string) (*Topic, error) { func AmGetTopicByName(ctx context.Context, conf *Conference, name string) (*Topic, error) {
var top Topic top := new(Topic)
err := amdb.GetContext(ctx, &top, "SELECT * FROM topics WHERE confid = ? AND name = ?", conf.ConfId, name) err := amdb.GetContext(ctx, top, "SELECT * FROM topics WHERE confid = ? AND name = ?", conf.ConfId, name)
if err == nil { if err == nil {
return &top, nil return top, nil
} }
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
err = ErrNoTopic err = ErrNoTopic
@@ -723,8 +723,8 @@ func AmListTopics(ctx context.Context, confid int32, uid int32, viewOption int,
* Pointer to the new Topic data structure. * Pointer to the new Topic data structure.
* Standard Go error status. * Standard Go error status.
*/ */
func AmNewTopic(ctx context.Context, conf *Conference, user *User, title string, zeroPostPseud string, zeroPost string, func AmNewTopic(ctx context.Context, conf *Conference, user *User, title, zeroPostPseud, zeroPost string, zeroPostLines int32,
zeroPostLines int32, comm *Community, ipaddr string) (*Topic, error) { comm *Community, ipaddr string) (*Topic, error) {
tx, commit, rollback := transaction(ctx) tx, commit, rollback := transaction(ctx)
defer rollback() defer rollback()
+22 -22
View File
@@ -473,12 +473,12 @@ func AmGetUser(ctx context.Context, uid int32) (*User, error) {
if rc, ok := userCache.Get(uid); ok { if rc, ok := userCache.Get(uid); ok {
return rc.(*User), nil return rc.(*User), nil
} }
var user User user := new(User)
err := amdb.GetContext(ctx, &user, "SELECT * from users WHERE uid = ?", uid) err := amdb.GetContext(ctx, user, "SELECT * from users WHERE uid = ?", uid)
switch err { switch err {
case nil: case nil:
userCache.Add(uid, &user) userCache.Add(uid, user)
return &user, nil return user, nil
case sql.ErrNoRows: case sql.ErrNoRows:
return nil, ErrNoUser return nil, ErrNoUser
} }
@@ -500,12 +500,12 @@ func AmGetUserTx(ctx context.Context, tx *sqlx.Tx, uid int32) (*User, error) {
if rc, ok := userCache.Get(uid); ok { if rc, ok := userCache.Get(uid); ok {
return rc.(*User), nil return rc.(*User), nil
} }
var user User user := new(User)
err := tx.GetContext(ctx, &user, "SELECT * from users WHERE uid = ?", uid) err := tx.GetContext(ctx, user, "SELECT * from users WHERE uid = ?", uid)
switch err { switch err {
case nil: case nil:
userCache.Add(uid, &user) userCache.Add(uid, user)
return &user, nil return user, nil
case sql.ErrNoRows: case sql.ErrNoRows:
return nil, ErrNoUser return nil, ErrNoUser
} }
@@ -522,12 +522,12 @@ func AmGetUserTx(ctx context.Context, tx *sqlx.Tx, uid int32) (*User, error) {
* Standard Go error status * Standard Go error status
*/ */
func AmGetUserByName(ctx context.Context, name string, tx *sqlx.Tx) (*User, error) { func AmGetUserByName(ctx context.Context, name string, tx *sqlx.Tx) (*User, error) {
var user User
var err error var err error
user := new(User)
if tx != nil { if tx != nil {
err = tx.GetContext(ctx, &user, "SELECT * FROM users WHERE username = ?", name) err = tx.GetContext(ctx, user, "SELECT * FROM users WHERE username = ?", name)
} else { } else {
err = amdb.GetContext(ctx, &user, "SELECT * FROM users WHERE username = ?", name) err = amdb.GetContext(ctx, user, "SELECT * FROM users WHERE username = ?", name)
} }
switch err { switch err {
case nil: case nil:
@@ -536,9 +536,9 @@ func AmGetUserByName(ctx context.Context, name string, tx *sqlx.Tx) (*User, erro
if rc, ok := userCache.Get(user.Uid); ok { if rc, ok := userCache.Get(user.Uid); ok {
return rc.(*User), nil return rc.(*User), nil
} else { } else {
userCache.Add(user.Uid, &user) userCache.Add(user.Uid, user)
} }
return &user, nil return user, nil
case sql.ErrNoRows: case sql.ErrNoRows:
return nil, ErrNoUser return nil, ErrNoUser
} }
@@ -821,12 +821,12 @@ func internalGetProp(ctx context.Context, uid int32, ndx int32) (*UserProperties
if rc, ok := userPropCache.Get(key); ok { if rc, ok := userPropCache.Get(key); ok {
return rc.(*UserProperties), nil return rc.(*UserProperties), nil
} }
var prop UserProperties prop := new(UserProperties)
if err := amdb.GetContext(ctx, &prop, "SELECT * from propuser WHERE uid = ? AND ndx = ?", uid, ndx); err != nil { if err := amdb.GetContext(ctx, prop, "SELECT * from propuser WHERE uid = ? AND ndx = ?", uid, ndx); err != nil {
return nil, err return nil, err
} }
userPropCache.Add(key, &prop) userPropCache.Add(key, prop)
return &prop, nil return prop, nil
} }
/* AmGetUserProperty retrieves the value of a user property. /* AmGetUserProperty retrieves the value of a user property.
@@ -891,13 +891,13 @@ func AmSetUserProperty(ctx context.Context, uid int32, ndx int32, val *string) e
* SearchUserOperRegex - The specified field matches the regular expression in "term". * SearchUserOperRegex - The specified field matches the regular expression in "term".
* term - The search term, as specified above. * term - The search term, as specified above.
* offset - Number of users to skip at beginning of list. * offset - Number of users to skip at beginning of list.
* max - Maximum number of users to return. * maxCount - Maximum number of users to return.
* Returns: * Returns:
* Array of User pointers representing the return elements. * Array of User pointers representing the return elements.
* The total number of users matching this query (could be greater than max) * The total number of users matching this query (could be greater than max)
* Standard Go error status. * Standard Go error status.
*/ */
func AmSearchUsers(ctx context.Context, field int, oper int, term string, offset int, max int) ([]*User, int, error) { func AmSearchUsers(ctx context.Context, field, oper int, term string, offset, maxCount int) ([]*User, int, error) {
var queryPortion strings.Builder var queryPortion strings.Builder
switch field { switch field {
case SearchUserFieldName: case SearchUserFieldName:
@@ -939,15 +939,15 @@ func AmSearchUsers(ctx context.Context, field int, oper int, term string, offset
var rs *sql.Rows var rs *sql.Rows
if offset > 0 { if offset > 0 {
rs, err = amdb.QueryContext(ctx, "SELECT u.uid FROM users u, contacts c WHERE u.contactid = c.contactid AND u.is_anon = 0 AND "+q+ rs, err = amdb.QueryContext(ctx, "SELECT u.uid FROM users u, contacts c WHERE u.contactid = c.contactid AND u.is_anon = 0 AND "+q+
" ORDER BY u.username LIMIT ? OFFSET ?", max, offset) " ORDER BY u.username LIMIT ? OFFSET ?", maxCount, offset)
} else { } else {
rs, err = amdb.QueryContext(ctx, "SELECT u.uid FROM users u, contacts c WHERE u.contactid = c.contactid AND u.is_anon = 0 AND "+q+ rs, err = amdb.QueryContext(ctx, "SELECT u.uid FROM users u, contacts c WHERE u.contactid = c.contactid AND u.is_anon = 0 AND "+q+
" ORDER BY u.username LIMIT ?", max) " ORDER BY u.username LIMIT ?", maxCount)
} }
if err != nil { if err != nil {
return nil, total, err return nil, total, err
} }
rc := make([]*User, 0, min(max, 10000)) rc := make([]*User, 0, min(maxCount, 10000))
for rs.Next() { for rs.Next() {
var uid int32 var uid int32
if err = rs.Scan(&uid); err == nil { if err = rs.Scan(&uid); err == nil {