-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,32 @@ | ||
package rank | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/rs/zerolog/log" | ||
"github.com/tminaorg/brzaguza/src/structures" | ||
) | ||
|
||
func SetRank(result *structures.Result) { | ||
result.Rank = result.SEPage*100 + result.SEPageRank | ||
// only one call for setResultResponse for a page will ever be performed, so there will never be a read and a write to result.Response at the same time | ||
// thus not locking relay.ResultMap[result.URL] in this function, because the result parameter is a copy is safe. It may, however, read memory that the map sees, | ||
// at the same time that the map is being written to, while this should be fine in this use-case, go may throw an error. | ||
// TLDR: you must mutex.Lock when changing *rankAddr, you probably dont need to mutex.RLock() when reading result | ||
// (in reality even *rankAddr shouldnt need a lock, but go would definately complain about simultanious read/write because of it) | ||
func SetRank(result *structures.Result, rankAddr *int, mutex *sync.RWMutex) { | ||
|
||
mutex.RLock() | ||
reqUrl := result.Response.Request.URL.String() //dummy code | ||
mutex.RUnlock() | ||
|
||
if reqUrl != result.URL { //dummy code | ||
log.Trace().Msg("Request URL not same as result.URL \\/") | ||
} | ||
|
||
rrank := result.SEPage*100 + result.SEPageRank | ||
|
||
mutex.Lock() | ||
*rankAddr = rrank | ||
mutex.Unlock() | ||
|
||
log.Trace().Msgf("Set rank to %v for %v: %v", result.Rank, result.Title, result.URL) | ||
log.Trace().Msgf("Set rank to %v for %v: %v", rrank, result.Title, result.URL) | ||
} |