Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add script to hibernate spaces #197

Merged
merged 23 commits into from
Nov 17, 2023
Merged

feat: add script to hibernate spaces #197

merged 23 commits into from
Nov 17, 2023

Conversation

wa0x6e
Copy link
Contributor

@wa0x6e wa0x6e commented Oct 8, 2023

Pitch: https://github.com/snapshot-labs/pitches/issues/65

Usage

  • yarn ts-node scripts/hibernate.ts run will hibernate inactive spaces
  • yarn ts-node scripts/hibernate.ts preview will show the number of spaces, eligible for hibernation

Note

This is PR is only about supporting the new hibernated column, as well as putting spaces to hibernation, and does not handled any kind validation (which requires coordination with UI, and come in a later PR)

@wa0x6e wa0x6e marked this pull request as ready for review November 1, 2023 11:14
@wa0x6e wa0x6e changed the title feat: add endpoint to toggle space hibernation feat: add hibernation support Nov 1, 2023
@ChaituVR ChaituVR self-requested a review November 8, 2023 11:58
@wa0x6e wa0x6e changed the title feat: add hibernation support feat: add script to hibernate spaces Nov 10, 2023
@wa0x6e
Copy link
Contributor Author

wa0x6e commented Nov 13, 2023

Script has been stripped down to hibernate only spaces inactive more than 1 year ago, and SQL queyr is now simple enough to not warrant a script.ts anymore.

Running the following SQL query will hibernate the spaces.

WITH toHibernate AS (
      WITH data AS (
        SELECT
        id,
        (SELECT MAX(end) FROM proposals WHERE space = spaces.id LIMIT 1) AS lastProposalEndDate
        FROM spaces
        WHERE hibernated = 0
      )

      SELECT
        id, lastProposalEndDate
        FROM data
        WHERE
        # Filtering out spaces that have not been active in the past year
        FROM_UNIXTIME(lastProposalEndDate) < DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR)
    )
    UPDATE spaces SET hibernated = 1 where id IN (id)

Feel free to merge this one, or just run the query separately, and close this PR

@wa0x6e wa0x6e requested a review from ChaituVR November 13, 2023 13:32
Copy link

codecov bot commented Nov 15, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (6e184d3) 44.78% compared to head (47281a0) 44.78%.
Report is 4 commits behind head on master.

Files Patch % Lines
src/helpers/actions.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #197   +/-   ##
=======================================
  Coverage   44.78%   44.78%           
=======================================
  Files          32       32           
  Lines        2041     2041           
  Branches      157      157           
=======================================
  Hits          914      914           
  Misses       1122     1122           
  Partials        5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@ChaituVR ChaituVR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utAck

@wa0x6e wa0x6e merged commit d62e6b6 into master Nov 17, 2023
@wa0x6e wa0x6e deleted the add-hibernation-toggler branch November 17, 2023 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants