Sobes.tech
Senior

Candidates' contacts are closed and paid when searching through the HH database — how to manage the limit on opening contacts?

sobes.tech AI

Answer from AI

There are several approaches to managing contact opening limits in the HH database:

  1. User or team quotas — set a maximum number of contact openings within a certain period (day, month). Once the limit is reached, access is blocked or additional limits are offered for purchase.

  2. Priority opening — allocate limits to the most valuable or promising candidates based on ratings or filters.

  3. Monitoring and reporting — keep track of limit usage with the ability to analyze and adjust policies.

  4. Automation of control — in Go code, implement middleware or a service that tracks the number of openings and blocks requests when the limit is exceeded.

An example of a simplified implementation of rate limiting in Go:

package main

import (
    "fmt"
    "sync"
    "time"
)

type RateLimiter struct {
    mu       sync.Mutex
    limits   map[string]int
    maxLimit int
}

func NewRateLimiter(max int) *RateLimiter {
    return &RateLimiter{
        limits:   make(map[string]int),
        maxLimit: max,
    }
}

func (r *RateLimiter) Allow(userID string) bool {
    r.mu.Lock()
    defer r.mu.Unlock()

    if r.limits[userID] >= r.maxLimit {
        return false
    }
    r.limits[userID]++
    return true
}

func (r *RateLimiter) Reset() {
    r.mu.Lock()
    defer r.mu.Unlock()
    r.limits = make(map[string]int)
}

func main() {
    rl := NewRateLimiter(5) // 5 openings per day

    user := "user123"
    for i := 0; i < 7; i++ {
        if rl.Allow(user) {
            fmt.Println("Contact opened")
        } else {
            fmt.Println("Limit exhausted")
        }
    }

    // Reset limits once a day
    go func() {
        for {
            time.Sleep(24 * time.Hour)
            rl.Reset()
        }
    }()
}

This approach helps control the use of paid contacts and optimize expenses.