(Tasklist): Make tasklists global.
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
CONFIG_FILE = "config/bot.conf"
|
||||
DATA_VERSION = 0
|
||||
DATA_VERSION = 1
|
||||
|
||||
@@ -129,7 +129,6 @@ class Tasklist:
|
||||
Update the in-memory tasklist from data and regenerate the pages
|
||||
"""
|
||||
self.tasklist = data.tasklist.fetch_rows_where(
|
||||
guildid=self.member.guild.id,
|
||||
userid=self.member.id,
|
||||
_extra=("AND last_updated_at > timezone('utc', NOW()) - INTERVAL '24h' "
|
||||
"ORDER BY created_at ASC, taskid ASC")
|
||||
@@ -331,7 +330,7 @@ class Tasklist:
|
||||
|
||||
if unrewarded:
|
||||
# Select tasks to reward up to the limit of rewards
|
||||
recent_rewards = data.tasklist_rewards.queries.count_recent_for(self.member.guild.id, self.member.id)
|
||||
recent_rewards = data.tasklist_rewards.queries.count_recent_for(self.member.id)
|
||||
max_to_reward = max((task_reward_limit - recent_rewards, 0))
|
||||
reward_tasks = unrewarded[:max_to_reward]
|
||||
|
||||
@@ -354,7 +353,6 @@ class Tasklist:
|
||||
|
||||
# Track reward
|
||||
data.tasklist_rewards.insert(
|
||||
guildid=self.member.guild.id,
|
||||
userid=self.member.id,
|
||||
reward_count=rewarding_count
|
||||
)
|
||||
@@ -376,12 +374,12 @@ class Tasklist:
|
||||
Add provided tasks to the task list
|
||||
"""
|
||||
insert = [
|
||||
(self.member.guild.id, self.member.id, task)
|
||||
(self.member.id, task)
|
||||
for task in tasks
|
||||
]
|
||||
return data.tasklist.insert_many(
|
||||
*insert,
|
||||
insert_keys=('guildid', 'userid', 'content')
|
||||
insert_keys=('userid', 'content')
|
||||
)
|
||||
|
||||
def _delete_tasks(self, *indexes):
|
||||
@@ -460,7 +458,6 @@ class Tasklist:
|
||||
# Fetch accurate count of current tasks
|
||||
count = data.tasklist.select_one_where(
|
||||
select_columns=("COUNT(*)",),
|
||||
guildid=self.member.guild.id,
|
||||
userid=self.member.id
|
||||
)[0]
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ from data import RowTable, Table
|
||||
|
||||
tasklist = RowTable(
|
||||
'tasklist',
|
||||
('taskid', 'guildid', 'userid', 'content', 'complete', 'rewarded', 'created_at', 'last_updated_at'),
|
||||
('taskid', 'userid', 'content', 'complete', 'rewarded', 'created_at', 'last_updated_at'),
|
||||
'taskid'
|
||||
)
|
||||
|
||||
@@ -25,13 +25,13 @@ tasklist_rewards = Table('tasklist_reward_history')
|
||||
|
||||
|
||||
@tasklist_rewards.save_query
|
||||
def count_recent_for(guildid, userid, interval='24h'):
|
||||
def count_recent_for(userid, interval='24h'):
|
||||
with tasklist_rewards.conn:
|
||||
with tasklist_rewards.conn.cursor() as curs:
|
||||
curs.execute(
|
||||
"SELECT SUM(reward_count) FROM tasklist_reward_history "
|
||||
"WHERE "
|
||||
"guildid = {} AND userid = {}"
|
||||
"AND reward_time > timezone('utc', NOW()) - INTERVAL '{}'".format(guildid, userid, interval)
|
||||
"userid = {}"
|
||||
"AND reward_time > timezone('utc', NOW()) - INTERVAL '{}'".format(userid, interval)
|
||||
)
|
||||
return curs.fetchone()[0] or 0
|
||||
|
||||
8
data/migration/v0-v1/migration.sql
Normal file
8
data/migration/v0-v1/migration.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
ALTER TABLE tasklist DROP COLUMN guildid;
|
||||
CREATE INDEX tasklist_users ON tasklist (userid);
|
||||
|
||||
ALTER TABLE tasklist_reward_history DROP COLUMN guildid;
|
||||
CREATE INDEX tasklist_reward_history_users ON tasklist_reward_history (userid, reward_time);
|
||||
|
||||
|
||||
INSERT INTO VersionHistory (version, author) VALUES (1, 'Migration v0-v1');
|
||||
1
data/migration/v0-v1/notes.md
Normal file
1
data/migration/v0-v1/notes.md
Normal file
@@ -0,0 +1 @@
|
||||
The purpose of this migration is to remove the guild dependency on tasklist tasks, so that a user's tasklist is available across all guilds.
|
||||
@@ -92,7 +92,6 @@ CREATE INDEX workout_sessions_members ON workout_sessions (guildid, userid);
|
||||
-- Tasklist data {{{
|
||||
CREATE TABLE tasklist(
|
||||
taskid SERIAL PRIMARY KEY,
|
||||
guildid BIGINT NOT NULL,
|
||||
userid BIGINT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
complete BOOL DEFAULT FALSE,
|
||||
@@ -100,7 +99,7 @@ CREATE TABLE tasklist(
|
||||
created_at TIMESTAMP DEFAULT (now() at time zone 'utc'),
|
||||
last_updated_at TIMESTAMP DEFAULT (now() at time zone 'utc')
|
||||
);
|
||||
CREATE INDEX tasklist_members ON tasklist (guildid, userid);
|
||||
CREATE INDEX tasklist_users ON tasklist (userid);
|
||||
|
||||
CREATE TABLE tasklist_channels(
|
||||
guildid BIGINT NOT NULL,
|
||||
@@ -109,12 +108,11 @@ CREATE TABLE tasklist_channels(
|
||||
CREATE INDEX tasklist_channels_guilds ON tasklist_channels (guildid);
|
||||
|
||||
CREATE TABLE tasklist_reward_history(
|
||||
guildid BIGINT NOT NULL,
|
||||
userid BIGINT NOT NULL,
|
||||
reward_time TIMESTAMP DEFAULT (now() at time zone 'utc'),
|
||||
reward_count INTEGER
|
||||
);
|
||||
CREATE INDEX tasklist_reward_history_members ON tasklist_reward_history (guildid, userid, reward_time);
|
||||
CREATE INDEX tasklist_reward_history_users ON tasklist_reward_history (userid, reward_time);
|
||||
-- }}}
|
||||
|
||||
-- Reminder data {{{
|
||||
|
||||
Reference in New Issue
Block a user