Changeset 652 in code for trunk/db_postgres.go


Ignore:
Timestamp:
Oct 18, 2021, 5:15:15 PM (4 years ago)
Author:
contact
Message:

Add context args to Database interface

This is a mecanical change, which just lifts up the context.TODO()
calls from inside the DB implementations to the callers.

Future work involves properly wiring up the contexts when it makes
sense.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/db_postgres.go

    r645 r652  
    148148}
    149149
    150 func (db *PostgresDB) Stats() (*DatabaseStats, error) {
    151         ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
     150func (db *PostgresDB) Stats(ctx context.Context) (*DatabaseStats, error) {
     151        ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
    152152        defer cancel()
    153153
     
    164164}
    165165
    166 func (db *PostgresDB) ListUsers() ([]User, error) {
    167         ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
     166func (db *PostgresDB) ListUsers(ctx context.Context) ([]User, error) {
     167        ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
    168168        defer cancel()
    169169
     
    193193}
    194194
    195 func (db *PostgresDB) GetUser(username string) (*User, error) {
    196         ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
     195func (db *PostgresDB) GetUser(ctx context.Context, username string) (*User, error) {
     196        ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
    197197        defer cancel()
    198198
     
    211211}
    212212
    213 func (db *PostgresDB) StoreUser(user *User) error {
    214         ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
     213func (db *PostgresDB) StoreUser(ctx context.Context, user *User) error {
     214        ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
    215215        defer cancel()
    216216
     
    235235}
    236236
    237 func (db *PostgresDB) DeleteUser(id int64) error {
    238         ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
     237func (db *PostgresDB) DeleteUser(ctx context.Context, id int64) error {
     238        ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
    239239        defer cancel()
    240240
     
    243243}
    244244
    245 func (db *PostgresDB) ListNetworks(userID int64) ([]Network, error) {
    246         ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
     245func (db *PostgresDB) ListNetworks(ctx context.Context, userID int64) ([]Network, error) {
     246        ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
    247247        defer cancel()
    248248
     
    287287}
    288288
    289 func (db *PostgresDB) StoreNetwork(userID int64, network *Network) error {
    290         ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
     289func (db *PostgresDB) StoreNetwork(ctx context.Context, userID int64, network *Network) error {
     290        ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
    291291        defer cancel()
    292292
     
    339339}
    340340
    341 func (db *PostgresDB) DeleteNetwork(id int64) error {
    342         ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
     341func (db *PostgresDB) DeleteNetwork(ctx context.Context, id int64) error {
     342        ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
    343343        defer cancel()
    344344
     
    347347}
    348348
    349 func (db *PostgresDB) ListChannels(networkID int64) ([]Channel, error) {
    350         ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
     349func (db *PostgresDB) ListChannels(ctx context.Context, networkID int64) ([]Channel, error) {
     350        ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
    351351        defer cancel()
    352352
     
    381381}
    382382
    383 func (db *PostgresDB) StoreChannel(networkID int64, ch *Channel) error {
    384         ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
     383func (db *PostgresDB) StoreChannel(ctx context.Context, networkID int64, ch *Channel) error {
     384        ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
    385385        defer cancel()
    386386
     
    409409}
    410410
    411 func (db *PostgresDB) DeleteChannel(id int64) error {
    412         ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
     411func (db *PostgresDB) DeleteChannel(ctx context.Context, id int64) error {
     412        ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
    413413        defer cancel()
    414414
     
    417417}
    418418
    419 func (db *PostgresDB) ListDeliveryReceipts(networkID int64) ([]DeliveryReceipt, error) {
    420         ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
     419func (db *PostgresDB) ListDeliveryReceipts(ctx context.Context, networkID int64) ([]DeliveryReceipt, error) {
     420        ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
    421421        defer cancel()
    422422
     
    445445}
    446446
    447 func (db *PostgresDB) StoreClientDeliveryReceipts(networkID int64, client string, receipts []DeliveryReceipt) error {
    448         ctx, cancel := context.WithTimeout(context.TODO(), postgresQueryTimeout)
     447func (db *PostgresDB) StoreClientDeliveryReceipts(ctx context.Context, networkID int64, client string, receipts []DeliveryReceipt) error {
     448        ctx, cancel := context.WithTimeout(ctx, postgresQueryTimeout)
    449449        defer cancel()
    450450
Note: See TracChangeset for help on using the changeset viewer.