diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-07-31 08:08:28 +0000 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-07-31 16:29:04 +0200 |
commit | 6c34df90b8f8eac80a417b155f039f771b6d8520 (patch) | |
tree | 9891fea58fc73bd724e7474733aa0ae07c31ad48 /kittystore | |
parent | 0ba168f33813a2b3fb01f6695f149a6742a11304 (diff) | |
download | kittystore-6c34df90b8f8eac80a417b155f039f771b6d8520.tar.gz kittystore-6c34df90b8f8eac80a417b155f039f771b6d8520.tar.xz kittystore-6c34df90b8f8eac80a417b155f039f771b6d8520.zip |
User profiles in HyperKitty
Diffstat (limited to 'kittystore')
-rw-r--r-- | kittystore/storm/schema/__init__.py | 3 | ||||
-rw-r--r-- | kittystore/storm/schema/patch_8.py | 2 | ||||
-rw-r--r-- | kittystore/storm/schema/patch_9.py | 26 | ||||
-rw-r--r-- | kittystore/storm/store.py | 27 |
4 files changed, 57 insertions, 1 deletions
diff --git a/kittystore/storm/schema/__init__.py b/kittystore/storm/schema/__init__.py index 6dc2f4c..7220b38 100644 --- a/kittystore/storm/schema/__init__.py +++ b/kittystore/storm/schema/__init__.py @@ -65,6 +65,7 @@ CREATES = { 'CREATE INDEX "ix_email_list_name" ON "email" (list_name);', 'CREATE INDEX "ix_email_date" ON "email" (date);', 'CREATE UNIQUE INDEX "ix_email_list_name_message_id_hash" ON "email" (list_name, message_id_hash);', + 'CREATE INDEX "ix_email_sender_email" ON "email" (sender_email);', 'CREATE INDEX "ix_email_subject" ON "email" (subject);', 'CREATE INDEX "ix_email_thread_id" ON "email" (thread_id);', 'CREATE INDEX "ix_email_thread_order" ON "email" (thread_order);', @@ -145,6 +146,7 @@ CREATES = { 'CREATE INDEX "ix_email_list_name" ON "email" USING btree (list_name);', 'CREATE INDEX "ix_email_date" ON "email" USING btree (date);', 'CREATE UNIQUE INDEX "ix_email_list_name_message_id_hash" ON "email" USING btree (list_name, message_id_hash);', + 'CREATE INDEX "ix_email_sender_email" ON "email" USING btree (sender_email);', 'CREATE INDEX "ix_email_subject" ON "email" USING btree (subject);', 'CREATE INDEX "ix_email_thread_id" ON "email" USING btree (thread_id);', 'CREATE INDEX "ix_email_thread_order" ON "email" USING btree (thread_order);', @@ -215,6 +217,7 @@ CREATES = { 'CREATE INDEX `ix_email_list_name` ON `email` (list_name);', 'CREATE INDEX `ix_email_date` ON `email` (date);', 'CREATE UNIQUE INDEX `ix_email_list_name_message_id_hash` ON `email` (list_name, message_id_hash);', + 'CREATE INDEX `ix_email_sender_email` ON `email` (sender_email(255));', 'CREATE INDEX `ix_email_subject` ON `email` (subject(255));', 'CREATE INDEX `ix_email_thread_id` ON `email` (thread_id);', 'CREATE INDEX `ix_email_thread_order` ON `email` (thread_order);', diff --git a/kittystore/storm/schema/patch_8.py b/kittystore/storm/schema/patch_8.py index a70c68a..8dcfbb4 100644 --- a/kittystore/storm/schema/patch_8.py +++ b/kittystore/storm/schema/patch_8.py @@ -48,7 +48,7 @@ SQL = { def apply(store): - """Add the subject_prefix column and delete the description column""" + """Add the category table""" dbtype = get_db_type(store) for statement in SQL[dbtype]: store.execute(statement) diff --git a/kittystore/storm/schema/patch_9.py b/kittystore/storm/schema/patch_9.py new file mode 100644 index 0000000..d1ae069 --- /dev/null +++ b/kittystore/storm/schema/patch_9.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +from __future__ import absolute_import + +from . import get_db_type + + +SQL = { + "sqlite": [ + 'CREATE INDEX "ix_sender_email" ON "email" (sender_email);', + ], + "postgres": [ + 'CREATE INDEX "ix_sender_email" ON "email" USING btree (sender_email);', + ], + "mysql": [ + 'CREATE INDEX `ix_sender_email` ON `email` (sender_email);', + ], + } + + +def apply(store): + """Add indexes on email.sender_email""" + dbtype = get_db_type(store) + for statement in SQL[dbtype]: + store.execute(statement) + store.commit() diff --git a/kittystore/storm/store.py b/kittystore/storm/store.py index 99d303b..1a19d58 100644 --- a/kittystore/storm/store.py +++ b/kittystore/storm/store.py @@ -543,6 +543,33 @@ class StormStore(object): return list(self.db.find(Category.name).order_by(Category.name)) + def get_first_post(self, list_name, email): + """ Returns a user's first post on a list """ + result = self.db.find(Email, And( + Email.list_name == unicode(list_name), + Email.sender_email == unicode(email), + )).order_by(Email.archived_date + ).config(limit=1).one() + return result + + def get_sender_name(self, email): + """ Returns a user's fullname when given his email """ + result = self.db.find(Email.sender_name, + Email.sender_email == unicode(email), + ).config(distinct=True, limit=1)[0] + return result + + def get_message_hashes_by_sender(self, email, list_name=None): + """ Returns a user's email hashes """ + if list_name is None: + clause = (Email.sender_email == unicode(email)) + else: + clause = And(Email.sender_email == unicode(email), + Email.list_name == unicode(list_name)) + result = self.db.find(Email.message_id_hash, clause) + return list(result) + + # Attachments def add_attachment(self, mlist, msg_id, counter, name, content_type, |