CleanExpiredRows deletes rows that are at least "expire" duration old. So if say an expire duration of 10 second is given, it will delete all rows that were updated 10 seconds ago
(expire time.Duration)
| 109 | // say an expire duration of 10 second is given, it will delete all rows that |
| 110 | // were updated 10 seconds ago |
| 111 | func (p *Postgres) CleanExpiredRows(expire time.Duration) (int64, error) { |
| 112 | // See: http://stackoverflow.com/questions/14465727/how-to-insert-things-like-now-interval-2-minutes-into-php-pdo-query |
| 113 | // basically by passing an integer to INTERVAL is not possible, we need to |
| 114 | // cast it. However there is a more simpler way, we can multiply INTERVAL |
| 115 | // with an integer so we just declare a one second INTERVAL and multiply it |
| 116 | // with the amount we want. |
| 117 | cleanOldRows := `DELETE FROM kite.kite WHERE updated_at < (now() at time zone 'utc') - ((INTERVAL '1 second') * $1)` |
| 118 | |
| 119 | rows, err := p.DB.Exec(cleanOldRows, int64(expire/time.Second)) |
| 120 | if err != nil { |
| 121 | return 0, err |
| 122 | } |
| 123 | |
| 124 | return rows.RowsAffected() |
| 125 | } |
| 126 | |
| 127 | func (p *Postgres) Get(query *protocol.KontrolQuery) (Kites, error) { |
| 128 | // only let query with usernames, otherwise the whole tree will be fetched |