Skip to content

Commit

Permalink
feat(interface): remove FIFO option when creating a score (#472)
Browse files Browse the repository at this point in the history
* feat(interface): remove FIFO option when creating a score

* feat(api): deprecating fifo deduplication

* chore(api): comment out FIFO code
  • Loading branch information
nutrina authored Nov 29, 2023
1 parent 908c985 commit 40bfc99
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 470 deletions.
2 changes: 1 addition & 1 deletion api/account/deduplication/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Rules(Enum):
LIFO = "LIFO"
FIFO = "FIFO"
FIFO = "FIFO" # DEPRECATED - this shall not be used any more

@classmethod
def choices(cls):
Expand Down
59 changes: 0 additions & 59 deletions api/account/deduplication/fifo.py

This file was deleted.

178 changes: 0 additions & 178 deletions api/account/test/test_deduplication_fifo.py

This file was deleted.

4 changes: 3 additions & 1 deletion api/registry/api/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ class GenericCommunityResponse(Schema):


class ActionEnum(str, Enum):
fifo_deduplication = Event.Action.FIFO_DEDUPLICATION
fifo_deduplication = (
Event.Action.FIFO_DEDUPLICATION
) # DEPRECATED: this deduplication method was deprecated
lifo_deduplication = Event.Action.LIFO_DEDUPLICATION
trustalab_score = Event.Action.TRUSTALAB_SCORE
score_update = Event.Action.SCORE_UPDATE
Expand Down
28 changes: 13 additions & 15 deletions api/registry/atasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Dict, List

import api_logging as logging
from account.deduplication.fifo import afifo
from account.deduplication.lifo import alifo

# --- Deduplication Modules
Expand Down Expand Up @@ -75,7 +74,6 @@ async def aprocess_deduplication(passport, community, passport_data, score: Scor
"""
rule_map = {
Rules.LIFO.value: alifo,
Rules.FIFO.value: afifo,
}

method = rule_map.get(community.rule)
Expand All @@ -100,19 +98,19 @@ async def aprocess_deduplication(passport, community, passport_data, score: Scor
)

# If the rule is FIFO, we need to re-score all affected passports
if community.rule == Rules.FIFO.value:
for passport in affected_passports:
log.debug(
"FIFO scoring selected, rescoring passport='%s'",
passport,
)

affected_score, _ = await Score.objects.aupdate_or_create(
passport=passport,
defaults=dict(score=None, status=score.status),
)
await acalculate_score(passport, passport.community_id, affected_score)
await affected_score.asave()
# if community.rule == Rules.FIFO.value:
# for passport in affected_passports:
# log.debug(
# "FIFO scoring selected, rescoring passport='%s'",
# passport,
# )

# affected_score, _ = await Score.objects.aupdate_or_create(
# passport=passport,
# defaults=dict(score=None, status=score.status),
# )
# await acalculate_score(passport, passport.community_id, affected_score)
# await affected_score.asave()

return deduplicated_passport

Expand Down
71 changes: 0 additions & 71 deletions api/registry/test/test_passport_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,77 +945,6 @@ def test_lifo_deduplication_duplicate_stamps(
self.assertEqual(updated_passport.address, submission_address)
self.assertEqual(updated_passport.stamps.all()[0].provider, "Google")

@patch("registry.atasks.validate_credential", side_effect=[[], []])
@patch(
"registry.atasks.aget_passport",
return_value=mock_passport_google,
)
def test_fifo_deduplication_duplicate_stamps(
self, aget_passport, validate_credential
):
"""
Test the successful deduplication of stamps by first in first out (FIFO)
"""
address_1 = self.account.address
address_2 = self.mock_account.address

fifo_community = Community.objects.create(
name="My FIFO Community",
description="My FIFO Community description",
account=self.user_account,
rule=Rules.FIFO.value,
)

# Create first passport
first_passport = Passport.objects.create(
address=address_1.lower(),
community=fifo_community,
requires_calculation=True,
)

Stamp.objects.create(
passport=first_passport,
hash=ens_credential["credentialSubject"]["hash"],
provider="Ens",
credential=ens_credential,
)

# Create existing stamp that is a duplicate of the one we are going to submit
Stamp.objects.create(
passport=first_passport,
hash=google_credential_2["credentialSubject"]["hash"],
provider="Google",
credential=google_credential_2,
)

# Now we submit a duplicate hash, and expect deduplication to happen
submission_test_payload = {
"community": fifo_community.pk,
"address": address_2,
"nonce": self.nonce,
}

submission_response = self.client.post(
f"{self.base_url}/submit-passport",
json.dumps(submission_test_payload),
content_type="application/json",
HTTP_AUTHORIZATION=f"Token {self.secret}",
)

self.assertEqual(submission_response.status_code, 200)

# first_passport should have just one stamp and the google stamps should be deleted
deduped_first_passport = Passport.objects.get(address=address_1)

self.assertEqual(deduped_first_passport.stamps.count(), 1)
self.assertEqual(deduped_first_passport.stamps.all()[0].provider, "Ens")

# assert submitted passport contains the google stamp
submitted_passport = Passport.objects.get(address=address_2)

self.assertEqual(submitted_passport.stamps.count(), 1)
self.assertEqual(submitted_passport.stamps.all()[0].provider, "Google")

@patch("registry.atasks.validate_credential", side_effect=[[], []])
@patch(
"registry.atasks.aget_passport",
Expand Down
Loading

0 comments on commit 40bfc99

Please sign in to comment.