Skip to content

Commit

Permalink
Merge pull request #2472 from BOINC/knr_right_to_erase
Browse files Browse the repository at this point in the history
Delete Account
  • Loading branch information
brevilo authored May 17, 2018
2 parents 1a3f1d7 + 83ea2bc commit 16bbbea
Show file tree
Hide file tree
Showing 28 changed files with 823 additions and 114 deletions.
38 changes: 38 additions & 0 deletions db/boinc_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ void PLATFORM::clear() {memset(this, 0, sizeof(*this));}
void APP::clear() {memset(this, 0, sizeof(*this));}
void APP_VERSION::clear() {memset(this, 0, sizeof(*this));}
void USER::clear() {memset(this, 0, sizeof(*this));}
void USER_DELETED::clear() {memset(this, 0, sizeof(*this));}
void TEAM::clear() {memset(this, 0, sizeof(*this));}
void HOST::clear() {memset(this, 0, sizeof(*this));}
void HOST_DELETED::clear() {memset(this, 0, sizeof(*this));}
void RESULT::clear() {
memset(this, 0, sizeof(*this));
size_class = -1;
Expand Down Expand Up @@ -119,10 +121,14 @@ DB_APP_VERSION::DB_APP_VERSION(DB_CONN* dc) :
DB_BASE("app_version", dc?dc:&boinc_db){}
DB_USER::DB_USER(DB_CONN* dc) :
DB_BASE("user", dc?dc:&boinc_db){}
DB_USER_DELETED::DB_USER_DELETED(DB_CONN* dc) :
DB_BASE("user_deleted", dc?dc:&boinc_db){}
DB_TEAM::DB_TEAM(DB_CONN* dc) :
DB_BASE("team", dc?dc:&boinc_db){}
DB_HOST::DB_HOST(DB_CONN* dc) :
DB_BASE("host", dc?dc:&boinc_db){}
DB_HOST_DELETED::DB_HOST_DELETED(DB_CONN* dc) :
DB_BASE("host_deleted", dc?dc:&boinc_db){}
DB_WORKUNIT::DB_WORKUNIT(DB_CONN* dc) :
DB_BASE("workunit", dc?dc:&boinc_db){}
DB_CREDITED_JOB::DB_CREDITED_JOB(DB_CONN* dc) :
Expand Down Expand Up @@ -192,8 +198,10 @@ DB_ID_TYPE DB_PLATFORM::get_id() {return id;}
DB_ID_TYPE DB_APP::get_id() {return id;}
DB_ID_TYPE DB_APP_VERSION::get_id() {return id;}
DB_ID_TYPE DB_USER::get_id() {return id;}
DB_ID_TYPE DB_USER_DELETED::get_id() {return userid;}
DB_ID_TYPE DB_TEAM::get_id() {return id;}
DB_ID_TYPE DB_HOST::get_id() {return id;}
DB_ID_TYPE DB_HOST_DELETED::get_id() {return hostid;}
DB_ID_TYPE DB_WORKUNIT::get_id() {return id;}
DB_ID_TYPE DB_RESULT::get_id() {return id;}
DB_ID_TYPE DB_MSG_FROM_HOST::get_id() {return id;}
Expand Down Expand Up @@ -425,6 +433,21 @@ void DB_USER::db_parse(MYSQL_ROW &r) {
email_addr_change_time = atof(r[i++]);
}

void DB_USER_DELETED::db_print(char* buf){
sprintf(buf,
"public_cross_project_id=%s, create_time=%.15e",
public_cross_project_id, create_time
);
}

void DB_USER_DELETED::db_parse(MYSQL_ROW &r) {
int i=0;
clear();
userid = atol(r[i++]);
strcpy2(public_cross_project_id, r[i++]);
create_time = atof(r[i++]);
}

void DB_TEAM::db_print(char* buf){
ESCAPE(name);
ESCAPE(name_lc);
Expand Down Expand Up @@ -894,6 +917,21 @@ int DB_HOST::fpops_stddev(double& stddev) {
return db->get_double(query, stddev);
}

void DB_HOST_DELETED::db_print(char* buf){
sprintf(buf,
"public_cross_project_id=%s, create_time=%.15e",
public_cross_project_id, create_time
);
}

void DB_HOST_DELETED::db_parse(MYSQL_ROW &r) {
int i=0;
clear();
hostid = atol(r[i++]);
strcpy2(public_cross_project_id, r[i++]);
create_time = atof(r[i++]);
}

void DB_WORKUNIT::db_print(char* buf){
sprintf(buf,
"create_time=%d, appid=%lu, "
Expand Down
18 changes: 18 additions & 0 deletions db/boinc_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ class DB_USER : public DB_BASE, public USER {
void operator=(USER& r) {USER::operator=(r);}
};

class DB_USER_DELETED : public DB_BASE, public USER_DELETED {
public:
DB_USER_DELETED(DB_CONN* p=0);
DB_ID_TYPE get_id();
void db_print(char*);
void db_parse(MYSQL_ROW &row);
void operator=(USER_DELETED& r) {USER_DELETED::operator=(r);}
};

class DB_TEAM : public DB_BASE, public TEAM {
public:
DB_TEAM(DB_CONN* p=0);
Expand All @@ -182,6 +191,15 @@ class DB_HOST : public DB_BASE, public HOST {
void operator=(HOST& r) {HOST::operator=(r);}
};

class DB_HOST_DELETED : public DB_BASE, public HOST_DELETED {
public:
DB_HOST_DELETED(DB_CONN* p=0);
DB_ID_TYPE get_id();
void db_print(char*);
void db_parse(MYSQL_ROW &row);
void operator=(HOST_DELETED& r) {HOST_DELETED::operator=(r);}
};

class DB_RESULT : public DB_BASE, public RESULT {
public:
DB_RESULT(DB_CONN* p=0);
Expand Down
14 changes: 14 additions & 0 deletions db/boinc_db_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ struct USER {
void clear();
};

struct USER_DELETED {
DB_ID_TYPE userid;
char public_cross_project_id[256];
double create_time;
void clear();
};

#define TEAM_TYPE_CLUB 1
#define TEAM_TYPE_COMPANY 2
#define TEAM_TYPE_PRIMARY 3
Expand Down Expand Up @@ -381,6 +388,13 @@ struct HOST {
bool get_opencl_cpu_prop(const char* platform, OPENCL_CPU_PROP&);
};

struct HOST_DELETED {
DB_ID_TYPE hostid;
char public_cross_project_id[256];
double create_time;
void clear();
};

// values for file_delete state
// see html/inc/common_defs.inc
#define FILE_DELETE_INIT 0
Expand Down
35 changes: 33 additions & 2 deletions db/constraints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ alter table result
-- scheduler (avoid sending mult results of same WU to one user)

alter table msg_from_host
add index message_handled (handled);
add index message_handled (handled),
-- for message handler
add index message_hostid(hostid);
-- for delete account

alter table msg_to_host
add index msg_to_host(hostid, handled);
Expand Down Expand Up @@ -114,7 +116,9 @@ alter table credited_job
add unique credited_job_user_wu (userid, workunitid);

alter table team_delta
add index team_delta_teamid (teamid, timestamp);
add index team_delta_teamid (teamid, timestamp),
add index team_delta_userid (userid);
-- for delete account

alter table team_admin
add unique (teamid, userid);
Expand Down Expand Up @@ -147,3 +151,30 @@ alter table credit_user
alter table credit_team
add index ct_total(appid, total),
add index ct_avg(appid, expavg);

alter table token
add index token_userid(userid);

alter table user_deleted
add index user_deleted_create(create_time);
-- for delete account

alter table host_deleted
add index host_deleted_create(create_time);
-- for delete account

alter table donation_paypal
-- for delete account
add index donation_paypal_userid(userid);

alter table banishment_vote
add index banishment_vote_userid(userid);
-- for delete account

alter table post_ratings
add index post_ratings_user(user);
-- for delete account

alter table sent_email
add index sent_email_userid(userid);
-- for delete account
18 changes: 16 additions & 2 deletions db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,20 @@ create table token (
type char not null,
create_time integer not null,
expire_time integer,
primary key (token),
index token_userid (userid)
primary key (token)
) engine=InnoDB;

create table user_deleted (
userid integer not null,
public_cross_project_id varchar(254) not null,
create_time double not null,
primary key (userid)
) engine=InnoDB;

create table host_deleted (
hostid integer not null,
public_cross_project_id varchar(254) not null,
create_time double not null,
primary key (hostid)
) engine=InnoDB;

55 changes: 55 additions & 0 deletions html/inc/boinc_db.inc
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ class BoincTeamDelta {
$db = BoincDb::get();
return $db->enum('team_delta', 'BoincTeamDelta', $where_clause);
}
static function delete_for_user($user_id) {
$db = BoincDb::get();
return $db->delete_aux('team_delta', "userid=$user_id");
}
}

class BoincHost {
Expand Down Expand Up @@ -343,6 +347,10 @@ class BoincHost {
if (!$ret) return $ret;
return $db->insert_id();
}
static function delete_for_user($user_id) {
$db = BoincDb::get();
return $db->delete_aux('host', "userid=$user_id");
}
}

class BoincResult {
Expand Down Expand Up @@ -602,6 +610,10 @@ class BoincHostAppVersion {
$db = BoincDb::get();
return $db->update_aux('host_app_version', $clause);
}
static function delete_for_user($user_id) {
$db = BoincDb::get();
return $db->delete_aux('host_app_version', "host_id in (select id from host where userid = $user_id)");
}
}

// DB utility functions
Expand Down Expand Up @@ -823,6 +835,49 @@ class BoincToken {
return $db->affected_rows();
}

static function delete_for_user($user_id) {
$db = BoincDb::get();
$db->delete_aux('token', "userid=$user_id");
return $db->affected_rows();
}

}

class BoincUserDeleted {

static function insert_user($user) {
$now = time();
$cpid = md5($user->cross_project_id.$user->email_addr);
$clause = "(userid, public_cross_project_id, create_time) values ($user->id, '$cpid', $now)";
$db = BoincDb::get();
return $db->insert('user_deleted', $clause);
}

static function delete_expired() {
$db = BoincDb::get();
$expire_time = time() - 60*86400; //60 days ago
$db->delete_aux('user_deleted', "create_time < $expire_time");
return $db->affected_rows();
}

}

class BoincHostDeleted {

static function insert_hosts_for_user($user) {
$now = time();
$clause = "select id, host_cpid, $now from host where userid = $user->id";
$db = BoincDb::get();
return $db->insert('host_deleted', $clause);
}

static function delete_expired() {
$db = BoincDb::get();
$expire_time = time() - 60*86400; //60 days ago
$db->delete_aux('host_deleted', "create_time < $expire_time");
return $db->affected_rows();
}

}


Expand Down
Loading

0 comments on commit 16bbbea

Please sign in to comment.