MCPcopy Create free account
hub / github.com/astercloud/aster / IncrementAccessCount

Method IncrementAccessCount

pkg/memory/logic/store_mysql.go:316–339  ·  view source on GitHub ↗

IncrementAccessCount 增加访问计数

(ctx context.Context, namespace, key string)

Source from the content-addressed store, hash-verified

314
315// IncrementAccessCount 增加访问计数
316func (s *MySQLStore) IncrementAccessCount(ctx context.Context, namespace, key string) error {
317 if s.closed {
318 return ErrStoreClosed
319 }
320
321 query := fmt.Sprintf(`
322 UPDATE %s
323 SET access_count = access_count + 1, last_accessed = ?, updated_at = ?
324 WHERE namespace = ? AND `+"`key`"+` = ?
325 `, s.tableName)
326
327 now := time.Now()
328 result, err := s.db.ExecContext(ctx, query, now, now, namespace, key)
329 if err != nil {
330 return NewStoreError("UPDATE_ERROR", "failed to increment access count", err)
331 }
332
333 rowsAffected, _ := result.RowsAffected()
334 if rowsAffected == 0 {
335 return ErrMemoryNotFound
336 }
337
338 return nil
339}
340
341// GetStats 获取统计信息
342func (s *MySQLStore) GetStats(ctx context.Context, namespace string) (*MemoryStats, error) {

Callers

nothing calls this directly

Calls 1

NewStoreErrorFunction · 0.85

Tested by

no test coverage detected