MCPcopy
hub / github.com/ddworken/hishtory / UpdateUsageData

Method UpdateUsageData

backend/server/internal/database/usagedata.go:45–56  ·  view source on GitHub ↗

UpdateUsageData updates the entry for a given userID/deviceID pair with the lastUsed and lastIP values

(ctx context.Context, userId, deviceId string, lastUsed time.Time, lastIP string)

Source from the content-addressed store, hash-verified

43
44// UpdateUsageData updates the entry for a given userID/deviceID pair with the lastUsed and lastIP values
45func (db *DB) UpdateUsageData(ctx context.Context, userId, deviceId string, lastUsed time.Time, lastIP string) error {
46 tx := db.DB.WithContext(ctx).Model(&UsageData{}).
47 Where("user_id = ? AND device_id = ?", userId, deviceId).
48 Update("last_used", lastUsed).
49 Update("last_ip", lastIP)
50
51 if tx.Error != nil {
52 return fmt.Errorf("db.WithContext.Model.Where.Update: %w", tx.Error)
53 }
54
55 return nil
56}
57
58func (db *DB) UpdateUsageDataForNumEntriesHandled(ctx context.Context, userId, deviceId string, numEntriesHandled int) error {
59 tx := db.DB.WithContext(ctx).Exec("UPDATE usage_data SET num_entries_handled = COALESCE(num_entries_handled, 0) + ? WHERE user_id = ? AND device_id = ?", numEntriesHandled, userId, deviceId)

Callers 1

updateUsageDataMethod · 0.80

Calls 1

UpdateMethod · 0.45

Tested by

no test coverage detected