MCPcopy Index your code
hub / github.com/koding/kite / CleanExpiredRows

Method CleanExpiredRows

kontrol/postgres.go:111–125  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

109// say an expire duration of 10 second is given, it will delete all rows that
110// were updated 10 seconds ago
111func (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
127func (p *Postgres) Get(query *protocol.KontrolQuery) (Kites, error) {
128 // only let query with usernames, otherwise the whole tree will be fetched

Callers 1

RunCleanerMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected