Skip to content

Commit

Permalink
Issue #91: Fixed display of related numbers in blocks of 10.
Browse files Browse the repository at this point in the history
  • Loading branch information
haumacher committed Dec 2, 2024
1 parent 5aec377 commit aa09a45
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ private static SearchResult analyze(String query, boolean isBot, boolean isSeach

info = db.getPhoneInfo(numberInfo, aggregation10, aggregation100);

if (aggregation100.getCnt() >= DB.MIN_AGGREGATE) {
if (aggregation100.getCnt() >= DB.MIN_AGGREGATE_100) {
relatedNumbers = reports.getRelatedNumbers(aggregation100.getPrefix());
} else {
if (aggregation100.getCnt() >= DB.MIN_AGGREGATE) {
if (aggregation10.getCnt() >= DB.MIN_AGGREGATE_10) {
relatedNumbers = reports.getRelatedNumbers(aggregation10.getPrefix());
} else {
relatedNumbers = Collections.emptyList();
Expand Down
14 changes: 8 additions & 6 deletions phoneblock/src/main/java/de/haumacher/phoneblock/db/DB.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public class DB {

private static final String BASIC_PREFIX = "Basic ";

public static final int MIN_AGGREGATE = 4;
public static final int MIN_AGGREGATE_10 = 4;

public static final int MIN_AGGREGATE_100 = 3;

private MessageDigest _sha256;

Expand Down Expand Up @@ -559,10 +561,10 @@ private void updateAggregation10(SpamReports reports, String phone, int deltaCnt
int votes = info.getVotes();

int cntBefore = cnt - deltaCnt;
if (cntBefore < MIN_AGGREGATE && cnt >= MIN_AGGREGATE) {
if (cntBefore < MIN_AGGREGATE_10 && cnt >= MIN_AGGREGATE_10) {
updateAggregation100(reports, phone, 1, votes);
}
else if (cntBefore >= MIN_AGGREGATE && cnt < MIN_AGGREGATE) {
else if (cntBefore >= MIN_AGGREGATE_10 && cnt < MIN_AGGREGATE_10) {
int votesBefore = votes - deltaVotes;

updateAggregation100(reports, phone, -1, -votesBefore);
Expand Down Expand Up @@ -976,18 +978,18 @@ public PhoneInfo getPhoneInfo(NumberInfo info, AggregationInfo aggregation10, Ag
.setLastUpdate(info.getUpdated());

int votes;
if (aggregation100.getVotes() >= MIN_AGGREGATE) {
if (aggregation100.getVotes() >= MIN_AGGREGATE_100) {
votes = aggregation100.getVotes();
if (!info.isActive()) {
// Direct votes did not count yet.
votes += info.getVotes();
}

if (aggregation10.getVotes() < MIN_AGGREGATE) {
if (aggregation10.getVotes() < MIN_AGGREGATE_10) {
// The votes of this number did not yet count to the aggregation of the block.
votes += aggregation10.getVotes();
}
} else if (aggregation10.getVotes() >= MIN_AGGREGATE) {
} else if (aggregation10.getVotes() >= MIN_AGGREGATE_10) {
votes = aggregation10.getVotes();
if (!info.isActive()) {
// Direct votes did not count yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ insert into NUMBERS (PHONE, VOTES, UPDATED, ADDED)
SELECT p.PHONE FROM NUMBERS p
WHERE p.PHONE > #{prefix}
AND p.PHONE < concat(#{prefix}, 'Z')
AND p.VOTES > 0
order by p.PHONE
""")
List<String> getRelatedNumbers(String prefix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ INSERT INTO NUMBERS (PHONE, ADDED, UPDATED, VOTES, ACTIVE) (
SELECT s.PHONE, s.DATEADDED, s.LASTUPDATE, s.VOTES, TRUE FROM SPAMREPORTS s
);

-- Insert old reports as active, too. The activation is computed later on with new rules.
INSERT INTO NUMBERS (PHONE, ADDED, UPDATED, VOTES, ACTIVE) (
SELECT s.PHONE, s.DATEADDED, s.LASTUPDATE, s.VOTES, FALSE FROM OLDREPORTS s
SELECT s.PHONE, s.DATEADDED, s.LASTUPDATE, s.VOTES, TRUE FROM OLDREPORTS s
LEFT OUTER JOIN SPAMREPORTS x
ON x.PHONE = s.PHONE
WHERE x.PHONE IS NULL
Expand Down Expand Up @@ -127,7 +128,7 @@ DELETE FROM NUMBERS_AGGREGATION_10 ;
INSERT INTO NUMBERS_AGGREGATION_10 (PREFIX, CNT, VOTES) (
SELECT a.prefix prefix, COUNT(1) cnt, SUM(a.votes) votes FROM (
SELECT SUBSTRING(s.PHONE, 0, LENGTH(s.phone) - 1) prefix, s.VOTES votes
FROM SPAMREPORTS s
FROM NUMBERS s
) a
GROUP BY a.prefix
);
Expand Down

0 comments on commit aa09a45

Please sign in to comment.