hicommonwealth / commonwealth

A platform for decentralized communities
https://commonwealth.im
GNU General Public License v3.0
67 stars 44 forks source link

🟩 Contests Projection #6820

Closed Rotorsoft closed 6 months ago

Rotorsoft commented 8 months ago

Description

Create a new projection for contest-related events, aimed at capturing all pertinent details at the contest level. This projection will facilitate the presentation of contest information across various UI views, encompassing started contests, new threads and votes within contests, as well as winners. The implementation should include a query endpoint with filters to efficiently retrieve contest records from this projection.

Stakeholders

Product Engineering
@zakhap @Rotorsoft

Details

Integration Patterns Consideration:

In the context of integration patterns, the following approaches are being considered:

By adopting these integration patterns, we aim to establish seamless communication channels between the platform and external systems, facilitating a more efficient and robust data exchange and synchronization.

Acceptance Criteria

Model

Contest Lifecycle

Engineering Requirements

:bangbang: Projection tickets are divided into a projection side (for updating data) and a query side (for querying data)

Projection

erDiagram
    Community ||--|{ ContestManager: has
    ContestManager ||--|{ Contest : has
    Contest ||--|{ ContestAction : has

    Community {
       string id PK
       string namespace
       blob the_other_stuff "other community attributes"
    }

    ContestManager {
       int community_id FK
       string contest_address PK "on-chain contest manager address"
       int interval "recurrent contest interval, 0 when one-off" 
       datetime created_at
    }

    Contest {
      string contest_address FK "on-chain contest manager address"
      int contest_id PK "on-chain recurrent contest id, 0 when one-off"
      datetime start_time 
      datetime end_time
      string[] winners "nullable, ranked contest-winning creator addresses"
    }

    ContestAction {
      string contest_address PK,FK "on-chain contest manager address"
      int contest_id PK,FK "on-chain recurrent contest id, 0 when one-off"
      int content_id PK "on-chain content id"
      string actor_address PK "actor address"
      enum action PK "added, upvoted, etc - action in PK will allow same address to add, vote, etc"
      string content_url "this is the url of participating threads (or any other content)"
      number voting_power "voting power of address when action was recorded"
      datetime created_at
    }

Queries

:bangbang: Queries should not raise non-auth related errors, instead return empty or filtered result sets... there might be exceptions to this rule

🟩 GetAllContests

Unit Testing

Rotorsoft commented 7 months ago

@kurtisassad let's start refining the engineering requirements and provide a rough estimate

CowMuon commented 6 months ago

Looks like Kurtis estimated at a 3. Tossing back to @Rotorsoft since Kurtis is out next week (and then when he is back, Ryan is out until 4/16.)

Needless to say, we would prefer not to have to wait for Kurtis to be back for this work to be done.

CowMuon commented 6 months ago

Roger will reach out to Protocol team today to confirm model/schema is correct.

rbennettcw commented 6 months ago

Looks like this can work. As discussed in the worker policy PR, maybe we can add chainNodeUrl to the ContentAdded/ContentUpvoted events so that we don't need to query across Thread->Community->ChainNode in the worker policy.

Should be fine unless for some reason the policy will fire months/years after the event was emitted at a time when the RPC url is no longer valid– edge case.

Rotorsoft commented 6 months ago

Looks like this can work. As discussed in the worker policy PR, maybe we can add chainNodeUrl to the ContentAdded/ContentUpvoted events so that we don't need to query across Thread->Community->ChainNode in the worker policy.

Should be fine unless for some reason the policy will fire months/years after the event was emitted at a time when the RPC url is no longer valid– edge case.

I think we can solve this in the projection/query... we can include chain node attributes in the general (getAll) query, or create a getById query with more details