mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-08-23 17:47:29 +00:00
initiateRead helper
This commit is contained in:
parent
4064c31025
commit
33d1caf670
1 changed files with 21 additions and 17 deletions
|
@ -123,6 +123,16 @@ func (tx *Tx) initiateWrite() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tx *Tx) initiateRead() error {
|
||||||
|
if tx.done {
|
||||||
|
return storage.ErrTxDone
|
||||||
|
}
|
||||||
|
if tx.multi == true {
|
||||||
|
return errors.New("Tried to read during MULTI")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (tx *Tx) Commit() error {
|
func (tx *Tx) Commit() error {
|
||||||
if tx.done {
|
if tx.done {
|
||||||
return storage.ErrTxDone
|
return storage.ErrTxDone
|
||||||
|
@ -147,15 +157,13 @@ func (tx *Tx) Rollback() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Tx) FindUser(passkey string) (*storage.User, bool, error) {
|
func (tx *Tx) FindUser(passkey string) (*storage.User, bool, error) {
|
||||||
if tx.done {
|
err := tx.initiateRead()
|
||||||
return nil, false, storage.ErrTxDone
|
if err != nil {
|
||||||
}
|
return nil, false, err
|
||||||
if tx.multi == true {
|
|
||||||
return nil, false, errors.New("Tried to read during MULTI")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
key := tx.conf.Prefix + "user:" + passkey
|
key := tx.conf.Prefix + "user:" + passkey
|
||||||
_, err := tx.Do("WATCH", key)
|
_, err = tx.Do("WATCH", key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
@ -176,15 +184,13 @@ func (tx *Tx) FindUser(passkey string) (*storage.User, bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Tx) FindTorrent(infohash string) (*storage.Torrent, bool, error) {
|
func (tx *Tx) FindTorrent(infohash string) (*storage.Torrent, bool, error) {
|
||||||
if tx.done {
|
err := tx.initiateRead()
|
||||||
return nil, false, storage.ErrTxDone
|
if err != nil {
|
||||||
}
|
return nil, false, err
|
||||||
if tx.multi == true {
|
|
||||||
return nil, false, errors.New("Tried to read during MULTI")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
key := tx.conf.Prefix + "torrent:" + infohash
|
key := tx.conf.Prefix + "torrent:" + infohash
|
||||||
_, err := tx.Do("WATCH", key)
|
_, err = tx.Do("WATCH", key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
@ -205,11 +211,9 @@ func (tx *Tx) FindTorrent(infohash string) (*storage.Torrent, bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Tx) ClientWhitelisted(peerID string) (exists bool, err error) {
|
func (tx *Tx) ClientWhitelisted(peerID string) (exists bool, err error) {
|
||||||
if tx.done {
|
err = tx.initiateRead()
|
||||||
return false, storage.ErrTxDone
|
if err != nil {
|
||||||
}
|
return false, err
|
||||||
if tx.multi == true {
|
|
||||||
return false, errors.New("Tried to read during MULTI")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
key := tx.conf.Prefix + "whitelist"
|
key := tx.conf.Prefix + "whitelist"
|
||||||
|
|
Loading…
Add table
Reference in a new issue