2017-11-10 03:33:11 +00:00
package common
2017-06-13 07:12:58 +00:00
2017-08-06 15:22:18 +00:00
import (
2022-02-21 03:32:53 +00:00
"database/sql"
"errors"
"strconv"
2017-08-06 15:22:18 +00:00
2022-02-21 03:32:53 +00:00
qgen "github.com/Azareal/Gosora/query_gen"
"golang.org/x/crypto/bcrypt"
2017-08-06 15:22:18 +00:00
)
2017-06-13 07:12:58 +00:00
2017-09-10 16:57:22 +00:00
// TODO: Add the watchdog goroutine
2017-09-15 22:20:01 +00:00
// TODO: Add some sort of update method
2017-11-11 04:06:16 +00:00
var Users UserStore
var ErrAccountExists = errors . New ( "this username is already in use" )
2018-03-17 08:16:43 +00:00
var ErrLongUsername = errors . New ( "this username is too long" )
2021-02-26 21:22:36 +00:00
var ErrSomeUsersNotFound = errors . New ( "Unable to find some users" )
2017-06-13 07:12:58 +00:00
type UserStore interface {
2022-02-21 03:32:53 +00:00
DirtyGet ( id int ) * User
Get ( id int ) ( * User , error )
Getn ( id int ) * User
GetByName ( name string ) ( * User , error )
BulkGetByName ( names [ ] string ) ( list [ ] * User , err error )
RawBulkGetByNameForConvo ( f func ( int , string , int , bool , int , int ) error , names [ ] string ) error
Exists ( id int ) bool
SearchOffset ( name , email string , gid , offset , perPage int ) ( users [ ] * User , err error )
GetOffset ( offset , perPage int ) ( [ ] * User , error )
Each ( f func ( * User ) error ) error
//BulkGet(ids []int) ([]*User, error)
BulkGetMap ( ids [ ] int ) ( map [ int ] * User , error )
BypassGet ( id int ) ( * User , error )
ClearLastIPs ( ) error
Create ( name , password , email string , group int , active bool ) ( int , error )
Reload ( id int ) error
Count ( ) int
CountSearch ( name , email string , gid int ) int
SetCache ( cache UserCache )
GetCache ( ) UserCache
2017-06-13 07:12:58 +00:00
}
2017-11-23 05:37:08 +00:00
type DefaultUserStore struct {
2022-02-21 03:32:53 +00:00
cache UserCache
2017-11-23 05:37:08 +00:00
2022-02-21 03:32:53 +00:00
get * sql . Stmt
getByName * sql . Stmt
searchOffset * sql . Stmt
getOffset * sql . Stmt
getAll * sql . Stmt
exists * sql . Stmt
register * sql . Stmt
nameExists * sql . Stmt
2021-01-18 22:11:30 +00:00
2022-02-21 03:32:53 +00:00
count * sql . Stmt
countSearch * sql . Stmt
2021-04-27 10:00:11 +00:00
2022-02-21 03:32:53 +00:00
clearIPs * sql . Stmt
2017-06-13 07:12:58 +00:00
}
2017-11-23 05:37:08 +00:00
// NewDefaultUserStore gives you a new instance of DefaultUserStore
func NewDefaultUserStore ( cache UserCache ) ( * DefaultUserStore , error ) {
2022-02-21 03:32:53 +00:00
acc := qgen . NewAcc ( )
if cache == nil {
cache = NewNullUserCache ( )
}
u := "users"
allCols := "uid,name,group,active,is_super_admin,session,email,avatar,message,level,score,posts,liked,last_ip,temp_group,createdAt,enable_embeds,profile_comments,who_can_convo"
// TODO: Add an admin version of registerStmt with more flexibility?
return & DefaultUserStore {
cache : cache ,
get : acc . Select ( u ) . Columns ( "name,group,active,is_super_admin,session,email,avatar,message,level,score,posts,liked,last_ip,temp_group,createdAt,enable_embeds,profile_comments,who_can_convo" ) . Where ( "uid=?" ) . Prepare ( ) ,
getByName : acc . Select ( u ) . Columns ( allCols ) . Where ( "name=?" ) . Prepare ( ) ,
searchOffset : acc . Select ( u ) . Columns ( allCols ) . Where ( "(name=? OR ?='') AND (email=? OR ?='') AND (group=? OR ?=0)" ) . Orderby ( "uid ASC" ) . Limit ( "?,?" ) . Prepare ( ) ,
getOffset : acc . Select ( u ) . Columns ( allCols ) . Orderby ( "uid ASC" ) . Limit ( "?,?" ) . Prepare ( ) ,
getAll : acc . Select ( u ) . Columns ( allCols ) . Prepare ( ) ,
exists : acc . Exists ( u , "uid" ) . Prepare ( ) ,
register : acc . Insert ( u ) . Columns ( "name,email,password,salt,group,is_super_admin,session,active,message,createdAt,lastActiveAt,lastLiked,oldestItemLikedCreatedAt" ) . Fields ( "?,?,?,?,?,0,'',?,'',UTC_TIMESTAMP(),UTC_TIMESTAMP(),UTC_TIMESTAMP(),UTC_TIMESTAMP()" ) . Prepare ( ) , // TODO: Implement user_count on users_groups here
nameExists : acc . Exists ( u , "name" ) . Prepare ( ) ,
count : acc . Count ( u ) . Prepare ( ) ,
countSearch : acc . Count ( u ) . Where ( "(name=? OR ?='') AND (email=? OR ?='') AND (group=? OR ?=0)" ) . Prepare ( ) ,
clearIPs : acc . Update ( u ) . Set ( "last_ip=''" ) . Where ( "last_ip!=''" ) . Prepare ( ) ,
} , acc . FirstError ( )
2017-06-13 07:12:58 +00:00
}
2019-08-28 06:47:54 +00:00
func ( s * DefaultUserStore ) DirtyGet ( id int ) * User {
2022-02-21 03:32:53 +00:00
user , err := s . Get ( id )
if err == nil {
return user
}
/ * if s . OutOfBounds ( id ) {
return BlankUser ( )
} * /
return BlankUser ( )
2017-11-11 04:06:16 +00:00
}
2021-02-26 21:22:36 +00:00
func ( s * DefaultUserStore ) scanUser ( r * sql . Row , u * User ) ( embeds int , err error ) {
2022-02-21 03:32:53 +00:00
e := r . Scan ( & u . Name , & u . Group , & u . Active , & u . IsSuperAdmin , & u . Session , & u . Email , & u . RawAvatar , & u . Message , & u . Level , & u . Score , & u . Posts , & u . Liked , & u . LastIP , & u . TempGroup , & u . CreatedAt , & embeds , & u . Privacy . ShowComments , & u . Privacy . AllowMessage )
return embeds , e
2021-02-26 21:22:36 +00:00
}
2017-11-23 05:37:08 +00:00
// TODO: Log weird cache errors? Not just here but in every *Cache?
2019-08-28 06:47:54 +00:00
func ( s * DefaultUserStore ) Get ( id int ) ( * User , error ) {
2022-02-21 03:32:53 +00:00
u , err := s . cache . Get ( id )
if err == nil {
//log.Print("cached user")
//log.Print(string(debug.Stack()))
//log.Println("")
return u , nil
}
//log.Print("uncached user")
u = & User { ID : id , Loggedin : true }
embeds , err := s . scanUser ( s . get . QueryRow ( id ) , u )
if err == nil {
if embeds != - 1 {
u . ParseSettings = DefaultParseSettings . CopyPtr ( )
u . ParseSettings . NoEmbed = embeds == 0
}
u . Init ( )
s . cache . Set ( u )
}
return u , err
2018-09-20 06:31:09 +00:00
}
2020-04-27 12:41:55 +00:00
func ( s * DefaultUserStore ) Getn ( id int ) * User {
2022-02-21 03:32:53 +00:00
u := s . cache . Getn ( id )
if u != nil {
return u
}
u = & User { ID : id , Loggedin : true }
embeds , err := s . scanUser ( s . get . QueryRow ( id ) , u )
if err != nil {
return nil
}
if embeds != - 1 {
u . ParseSettings = DefaultParseSettings . CopyPtr ( )
u . ParseSettings . NoEmbed = embeds == 0
}
u . Init ( )
s . cache . Set ( u )
return u
2020-04-27 12:41:55 +00:00
}
2018-09-20 06:31:09 +00:00
// TODO: Log weird cache errors? Not just here but in every *Cache?
// ! This bypasses the cache, use frugally
2019-08-28 06:47:54 +00:00
func ( s * DefaultUserStore ) GetByName ( name string ) ( * User , error ) {
2022-02-21 03:32:53 +00:00
u := & User { Loggedin : true }
var embeds int
err := s . getByName . QueryRow ( name ) . Scan ( & u . ID , & u . Name , & u . Group , & u . Active , & u . IsSuperAdmin , & u . Session , & u . Email , & u . RawAvatar , & u . Message , & u . Level , & u . Score , & u . Posts , & u . Liked , & u . LastIP , & u . TempGroup , & u . CreatedAt , & embeds , & u . Privacy . ShowComments , & u . Privacy . AllowMessage )
if err != nil {
return nil , err
}
if embeds != - 1 {
u . ParseSettings = DefaultParseSettings . CopyPtr ( )
u . ParseSettings . NoEmbed = embeds == 0
}
u . Init ( )
s . cache . Set ( u )
return u , nil
2017-06-13 07:12:58 +00:00
}
2021-02-26 21:22:36 +00:00
// TODO: Optimise the query to avoid preparing it on the spot? Maybe, use knowledge of the most common IN() parameter counts?
// ! This bypasses the cache, use frugally
func ( s * DefaultUserStore ) BulkGetByName ( names [ ] string ) ( list [ ] * User , err error ) {
2022-02-21 03:32:53 +00:00
if len ( names ) == 0 {
return list , nil
} else if len ( names ) == 1 {
user , err := s . GetByName ( names [ 0 ] )
if err != nil {
return list , err
}
return [ ] * User { user } , nil
}
idList , q := inqbuildstr ( names )
rows , err := qgen . NewAcc ( ) . Select ( "users" ) . Columns ( "uid,name,group,active,is_super_admin,session,email,avatar,message,level,score,posts,liked,last_ip,temp_group,createdAt,enable_embeds,profile_comments,who_can_convo" ) . Where ( "name IN(" + q + ")" ) . Query ( idList ... )
if err != nil {
return list , err
}
defer rows . Close ( )
var embeds int
for rows . Next ( ) {
u := & User { Loggedin : true }
err := rows . Scan ( & u . ID , & u . Name , & u . Group , & u . Active , & u . IsSuperAdmin , & u . Session , & u . Email , & u . RawAvatar , & u . Message , & u . Level , & u . Score , & u . Posts , & u . Liked , & u . LastIP , & u . TempGroup , & u . CreatedAt , & embeds , & u . Privacy . ShowComments , & u . Privacy . AllowMessage )
if err != nil {
return list , err
}
if embeds != - 1 {
u . ParseSettings = DefaultParseSettings . CopyPtr ( )
u . ParseSettings . NoEmbed = embeds == 0
}
u . Init ( )
s . cache . Set ( u )
list = append ( list , u )
}
if err = rows . Err ( ) ; err != nil {
return list , err
}
// Did we miss any users?
if len ( names ) > len ( list ) {
return list , ErrSomeUsersNotFound
}
return list , err
2021-02-26 21:22:36 +00:00
}
// Special case function for efficiency
func ( s * DefaultUserStore ) RawBulkGetByNameForConvo ( f func ( int , string , int , bool , int , int ) error , names [ ] string ) error {
2022-02-21 03:32:53 +00:00
idList , q := inqbuildstr ( names )
rows , e := qgen . NewAcc ( ) . Select ( "users" ) . Columns ( "uid,name,group,is_super_admin,temp_group,who_can_convo" ) . Where ( "name IN(" + q + ")" ) . Query ( idList ... )
if e != nil {
return e
}
defer rows . Close ( )
for rows . Next ( ) {
var name string
var id , group , temp_group , who_can_convo int
var super_admin bool
if e = rows . Scan ( & id , & name , & group , & super_admin , & temp_group , & who_can_convo ) ; e != nil {
return e
}
if e = f ( id , name , group , super_admin , temp_group , who_can_convo ) ; e != nil {
return e
}
}
return rows . Err ( )
2021-02-26 21:22:36 +00:00
}
2018-05-27 09:36:35 +00:00
// TODO: Optimise this, so we don't wind up hitting the database every-time for small gaps
// TODO: Make this a little more consistent with DefaultGroupStore's GetRange method
2020-01-14 05:07:00 +00:00
func ( s * DefaultUserStore ) GetOffset ( offset , perPage int ) ( users [ ] * User , err error ) {
2022-02-21 03:32:53 +00:00
rows , err := s . getOffset . Query ( offset , perPage )
if err != nil {
return users , err
}
defer rows . Close ( )
var embeds int
for rows . Next ( ) {
u := & User { Loggedin : true }
err := rows . Scan ( & u . ID , & u . Name , & u . Group , & u . Active , & u . IsSuperAdmin , & u . Session , & u . Email , & u . RawAvatar , & u . Message , & u . Level , & u . Score , & u . Posts , & u . Liked , & u . LastIP , & u . TempGroup , & u . CreatedAt , & embeds , & u . Privacy . ShowComments , & u . Privacy . AllowMessage )
if err != nil {
return nil , err
}
if embeds != - 1 {
u . ParseSettings = DefaultParseSettings . CopyPtr ( )
u . ParseSettings . NoEmbed = embeds == 0
}
u . Init ( )
s . cache . Set ( u )
users = append ( users , u )
}
return users , rows . Err ( )
2018-05-27 09:36:35 +00:00
}
2021-01-19 23:47:08 +00:00
func ( s * DefaultUserStore ) SearchOffset ( name , email string , gid , offset , perPage int ) ( users [ ] * User , err error ) {
2022-02-21 03:32:53 +00:00
rows , err := s . searchOffset . Query ( name , name , email , email , gid , gid , offset , perPage )
if err != nil {
return users , err
}
defer rows . Close ( )
var embeds int
for rows . Next ( ) {
u := & User { Loggedin : true }
err := rows . Scan ( & u . ID , & u . Name , & u . Group , & u . Active , & u . IsSuperAdmin , & u . Session , & u . Email , & u . RawAvatar , & u . Message , & u . Level , & u . Score , & u . Posts , & u . Liked , & u . LastIP , & u . TempGroup , & u . CreatedAt , & embeds , & u . Privacy . ShowComments , & u . Privacy . AllowMessage )
if err != nil {
return nil , err
}
if embeds != - 1 {
u . ParseSettings = DefaultParseSettings . CopyPtr ( )
u . ParseSettings . NoEmbed = embeds == 0
}
u . Init ( )
s . cache . Set ( u )
users = append ( users , u )
}
return users , rows . Err ( )
2021-01-18 22:11:30 +00:00
}
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
func ( s * DefaultUserStore ) Each ( f func ( * User ) error ) error {
2022-02-21 03:32:53 +00:00
rows , e := s . getAll . Query ( )
if e != nil {
return e
}
defer rows . Close ( )
var embeds int
for rows . Next ( ) {
u := new ( User )
if e := rows . Scan ( & u . ID , & u . Name , & u . Group , & u . Active , & u . IsSuperAdmin , & u . Session , & u . Email , & u . RawAvatar , & u . Message , & u . Level , & u . Score , & u . Posts , & u . Liked , & u . LastIP , & u . TempGroup , & u . CreatedAt , & embeds , & u . Privacy . ShowComments , & u . Privacy . AllowMessage ) ; e != nil {
return e
}
if embeds != - 1 {
u . ParseSettings = DefaultParseSettings . CopyPtr ( )
u . ParseSettings . NoEmbed = embeds == 0
}
u . Init ( )
if e := f ( u ) ; e != nil {
return e
}
}
return rows . Err ( )
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
}
2018-05-27 09:36:35 +00:00
2017-09-10 16:57:22 +00:00
// TODO: Optimise the query to avoid preparing it on the spot? Maybe, use knowledge of the most common IN() parameter counts?
// TODO: ID of 0 should always error?
2019-07-25 07:00:49 +00:00
func ( s * DefaultUserStore ) BulkGetMap ( ids [ ] int ) ( list map [ int ] * User , err error ) {
2022-02-21 03:32:53 +00:00
idCount := len ( ids )
list = make ( map [ int ] * User )
if idCount == 0 {
return list , nil
}
var stillHere [ ] int
sliceList := s . cache . BulkGet ( ids )
if len ( sliceList ) > 0 {
for i , sliceItem := range sliceList {
if sliceItem != nil {
list [ sliceItem . ID ] = sliceItem
} else {
stillHere = append ( stillHere , ids [ i ] )
}
}
ids = stillHere
}
// If every user is in the cache, then return immediately
if len ( ids ) == 0 {
return list , nil
} else if len ( ids ) == 1 {
user , err := s . Get ( ids [ 0 ] )
if err != nil {
return list , err
}
list [ user . ID ] = user
return list , nil
}
idList , q := inqbuild ( ids )
rows , err := qgen . NewAcc ( ) . Select ( "users" ) . Columns ( "uid,name,group,active,is_super_admin,session,email,avatar,message,level,score,posts,liked,last_ip,temp_group,createdAt,enable_embeds,profile_comments,who_can_convo" ) . Where ( "uid IN(" + q + ")" ) . Query ( idList ... )
if err != nil {
return list , err
}
defer rows . Close ( )
var embeds int
for rows . Next ( ) {
u := & User { Loggedin : true }
err := rows . Scan ( & u . ID , & u . Name , & u . Group , & u . Active , & u . IsSuperAdmin , & u . Session , & u . Email , & u . RawAvatar , & u . Message , & u . Level , & u . Score , & u . Posts , & u . Liked , & u . LastIP , & u . TempGroup , & u . CreatedAt , & embeds , & u . Privacy . ShowComments , & u . Privacy . AllowMessage )
if err != nil {
return list , err
}
if embeds != - 1 {
u . ParseSettings = DefaultParseSettings . CopyPtr ( )
u . ParseSettings . NoEmbed = embeds == 0
}
u . Init ( )
s . cache . Set ( u )
list [ u . ID ] = u
}
if err = rows . Err ( ) ; err != nil {
return list , err
}
// Did we miss any users?
if idCount > len ( list ) {
var sidList string
for _ , id := range ids {
_ , ok := list [ id ]
if ! ok {
sidList += strconv . Itoa ( id ) + ","
}
}
if sidList != "" {
sidList = sidList [ 0 : len ( sidList ) - 1 ]
err = errors . New ( "Unable to find users with the following IDs: " + sidList )
}
}
return list , err
2017-08-06 15:22:18 +00:00
}
2019-08-28 06:47:54 +00:00
func ( s * DefaultUserStore ) BypassGet ( id int ) ( * User , error ) {
2022-02-21 03:32:53 +00:00
u := & User { ID : id , Loggedin : true }
embeds , err := s . scanUser ( s . get . QueryRow ( id ) , u )
if err == nil {
if embeds != - 1 {
u . ParseSettings = DefaultParseSettings . CopyPtr ( )
u . ParseSettings . NoEmbed = embeds == 0
}
u . Init ( )
}
return u , err
2017-06-13 07:12:58 +00:00
}
2019-08-28 06:47:54 +00:00
func ( s * DefaultUserStore ) Reload ( id int ) error {
2022-02-21 03:32:53 +00:00
u , err := s . BypassGet ( id )
if err != nil {
s . cache . Remove ( id )
return err
}
_ = s . cache . Set ( u )
TopicListThaw . Thaw ( )
return nil
2017-06-13 07:12:58 +00:00
}
2019-08-28 06:47:54 +00:00
func ( s * DefaultUserStore ) Exists ( id int ) bool {
2022-02-21 03:32:53 +00:00
err := s . exists . QueryRow ( id ) . Scan ( & id )
if err != nil && err != ErrNoRows {
LogError ( err )
}
return err != ErrNoRows
2017-09-15 22:20:01 +00:00
}
2021-04-27 10:00:11 +00:00
func ( s * DefaultUserStore ) ClearLastIPs ( ) error {
2022-02-21 03:32:53 +00:00
_ , e := s . clearIPs . Exec ( )
return e
2021-04-27 10:00:11 +00:00
}
2017-10-16 07:32:58 +00:00
// TODO: Change active to a bool?
2018-05-28 06:27:12 +00:00
// TODO: Use unique keys for the usernames
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
func ( s * DefaultUserStore ) Create ( name , password , email string , group int , active bool ) ( int , error ) {
2022-02-21 03:32:53 +00:00
// TODO: Strip spaces?
// ? This number might be a little screwy with Unicode, but it's the only consistent thing we have, as Unicode characters can be any number of bytes in theory?
if len ( name ) > Config . MaxUsernameLength {
return 0 , ErrLongUsername
}
// Is this name already taken..?
err := s . nameExists . QueryRow ( name ) . Scan ( & name )
if err != ErrNoRows {
return 0 , ErrAccountExists
}
salt , err := GenerateSafeString ( SaltLength )
if err != nil {
return 0 , err
}
hashedPassword , err := bcrypt . GenerateFromPassword ( [ ] byte ( password + salt ) , bcrypt . DefaultCost )
if err != nil {
return 0 , err
}
res , err := s . register . Exec ( name , email , string ( hashedPassword ) , salt , group , active )
if err != nil {
return 0 , err
}
lastID , err := res . LastInsertId ( )
return int ( lastID ) , err
2017-06-25 09:56:39 +00:00
}
2019-06-01 12:31:48 +00:00
// Count returns the total number of users registered on the forums
func ( s * DefaultUserStore ) Count ( ) ( count int ) {
2022-02-21 03:32:53 +00:00
return Countf ( s . count )
2017-08-15 13:47:56 +00:00
}
2021-01-19 23:47:08 +00:00
func ( s * DefaultUserStore ) CountSearch ( name , email string , gid int ) ( count int ) {
2022-02-21 03:32:53 +00:00
return Countf ( s . countSearch , name , name , email , email , gid , gid )
2021-01-18 22:11:30 +00:00
}
2019-06-01 12:31:48 +00:00
func ( s * DefaultUserStore ) SetCache ( cache UserCache ) {
2022-02-21 03:32:53 +00:00
s . cache = cache
2017-06-13 07:12:58 +00:00
}
2017-11-23 05:37:08 +00:00
// TODO: We're temporarily doing this so that you can do ucache != nil in getTopicUser. Refactor it.
2019-06-01 12:31:48 +00:00
func ( s * DefaultUserStore ) GetCache ( ) UserCache {
2022-02-21 03:32:53 +00:00
_ , ok := s . cache . ( * NullUserCache )
if ok {
return nil
}
return s . cache
2017-10-21 00:27:47 +00:00
}