/soc/2015/igor.gajowiak/chatlog: 36ddf6ef71cc: Added Days table ...

Igor Gajowiak <[email protected]>
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: 36ddf6ef71cc3c5b2e780631b721839b4644213a
Author:	 Igor Gajowiak <[email protected]>
Date:	 2015-07-30 02:03 +0200
Branch:	 default
URL: https://hg.pidgin.im/soc/2015/igor.gajowiak/chatlog/rev/36ddf6ef71cc

Description:

Added Days table and made some more SQL optimizations.

diffstat:

 libpurple/genericlog.c            |   14 +-
 libpurple/genericlog.h            |   47 ++-
 libpurple/plugins/log/logsqlite.c |  498 ++++++++++++++++++++++++++++---------
 3 files changed, 423 insertions(+), 136 deletions(-)

diffs (truncated from 1001 to 300 lines):

diff --git a/libpurple/genericlog.c b/libpurple/genericlog.c
--- a/libpurple/genericlog.c
+++ b/libpurple/genericlog.c
@@ -248,12 +248,12 @@ purple_genericlog_get_unseen_msgs(Purple
 }
 
 gboolean
-purple_genericlog_get_all_msgs(PurpleBuddy *buddy, GList **result,
+purple_genericlog_get_all_msgs(PurpleBuddy *buddy, guint64 day, GList **result,
 	GError **error)
 {
 	DEFINE_GENERICLOG_FUNC_WITH_RETURN(get_all_msgs,
 		"%s does not support getting all messages",
-		"Getting all messages from %s failed", buddy, result);
+		"Getting all messages from %s failed", buddy, day, result);
 }
 
 gboolean
@@ -274,6 +274,15 @@ purple_genericlog_get_all_buddies(GList*
 		"Getting buddies from %s failed", result);
 }
 
+gboolean
+purple_genericlog_get_all_days(PurpleBuddy *buddy, GArray **result,
+	GError **error)
+{
+	DEFINE_GENERICLOG_FUNC_WITH_RETURN(get_all_days,
+		"%s does not support getting all days",
+		"Getting all days from %s failed", buddy, result);
+}
+
 #undef DEFINE_GENERICLOG_FUNC_WITH_RETURN
 
 /**************************************************************************/
@@ -363,6 +372,7 @@ purple_genericlog_class_init(PurpleGener
 	klass->get_all_msgs = NULL;
 	klass->get_older_msgs = NULL;
 	klass->get_all_buddies = NULL;
+	klass->get_all_days = NULL;
 
 	klass->reserved1 = NULL;
 	klass->reserved2 = NULL;
diff --git a/libpurple/genericlog.h b/libpurple/genericlog.h
--- a/libpurple/genericlog.h
+++ b/libpurple/genericlog.h
@@ -61,9 +61,12 @@ struct _PurpleGenericLog
  *                   In case of any error the result is not set.
  *                   The client is responsible for freeing the result with
  *                   g_list_free_full(result, g_object_unref).
- * @get_all_msgs:    Gets all messages sent to or received from a buddy.
- *                   Messages are sorted by their timestamp in ascending order.
- *                   Returns %TRUE if operation succeeds, %FALSE otherwise.
+ * @get_all_msgs:    Gets all messages sent to or received from a buddy on
+ *                   a given day. Messages are sorted by their timestamp
+ *                   in ascending order. Returns %TRUE if operation succeeds,
+ *                   %FALSE otherwise. In case of any error the result is not
+ *                   set. The client is responsible for freeing the result with
+ *                   g_list_free_full(result, g_object_unref).
  * @get_older_msgs:  Gets all messages sent to or received from a buddy, older
  *                   than the message and not older than the timestamp.
  *                   If message is %NULL then upper bound check is skipped.
@@ -73,6 +76,11 @@ struct _PurpleGenericLog
  *                   message in the log. Returns %TRUE if operation succeeds,
  *                   %FALSE otherwise. The client is responsible for freeing
  *                   the result with g_list_free_full(result, g_object_unref).
+ * @get_all_days:    Gets an array of all days with at least one message
+ *                   received from or sent to a given buddy. Day is represented
+ *                   as unix timestamp (guint64) (at 00:00). Returns %TRUE
+ *                   if operation succeeds, %FALSE otherwise. The client
+ *                   is responsible for freeing the result with g_array_unref.
  *
  * The abstract base class for all log implementations. A conforming plugin
  * must implement at least activate and deactivate methods. Not supported
@@ -93,13 +101,15 @@ struct _PurpleGenericLogClass
 
 	gboolean (*get_unseen_msgs)(PurpleAccount *account, GList **result);
 
-	gboolean (*get_all_msgs)(PurpleBuddy *buddy, GList **result);
+	gboolean (*get_all_msgs)(PurpleBuddy *buddy, guint64 day, GList **result);
 
 	gboolean (*get_older_msgs)(PurpleBuddy *buddy, guint64 timestamp,
 		PurpleMessage *message, GList **result);
 
 	gboolean (*get_all_buddies)(GList **result);
 
+	gboolean (*get_all_days)(PurpleBuddy *buddy, GArray **result);
+
 	void (*reserved1)(void);
 	void (*reserved2)(void);
 	void (*reserved3)(void);
@@ -251,21 +261,23 @@ purple_genericlog_get_unseen_msgs(Purple
 /**
  * purple_genericlog_get_all_msgs:
  * @buddy:       The buddy.
+ * @day:         The day received from previous call to
+ *               purple_genericlog_get_all_days.
  * @result[out]: Return location for a #GList of #PurpleMessage objects.
  *               This will not be set in case of any errors.
  * @error:       Return location for a #GError or %NULL. If provided, this
  *               will be set to the reason if getting messages fails.
  *
- * Gets all messages from the active log sent to or received from a buddy.
+ * Gets all messages sent to or received from a given buddy on a given day.
  *
  * Messages are sorted by their timestamp in ascending order.
- * The caller is responsible for freeing the result with
- * g_list_free_full(result, g_object_unref).
+ * The caller is responsible for freeing the
+ * result with g_list_free_full(result, g_object_unref)
  *
  * Returns: %TRUE if succeeds, %FALSE otherwise.
  */
 gboolean
-purple_genericlog_get_all_msgs(PurpleBuddy *buddy, GList **result,
+purple_genericlog_get_all_msgs(PurpleBuddy *buddy, guint64 day, GList **result,
 	GError **error);
 
 /**
@@ -308,6 +320,25 @@ purple_genericlog_get_older_msgs(PurpleB
 gboolean
 purple_genericlog_get_all_buddies(GList **result, GError **error);
 
+/**
+ * purple_genericlog_get_all_days:
+ * @buddy:  The buddy.
+ * @result: Return location for a #GArray containing elements of type guint64
+ *          representing days. This will not be set in case of any errors.
+ * @error:  Return location for a #GError or %NULL. If provided, this
+ *          will be set to the reason if getting days fails.
+ *
+ * Gets an array of all days with at least one message received from
+ * or sent to a buddy.
+ *
+ * The caller is responsible for freeing the result with g_array_unref.
+ *
+ * Returns: %TRUE if succeeds, %FALSE otherwise.
+ */
+gboolean
+purple_genericlog_get_all_days(PurpleBuddy *buddy, GArray **result,
+	GError **error);
+
 /**************************************************************************/
 /* Error Codes                                                            */
 /**************************************************************************/
diff --git a/libpurple/plugins/log/logsqlite.c b/libpurple/plugins/log/logsqlite.c
--- a/libpurple/plugins/log/logsqlite.c
+++ b/libpurple/plugins/log/logsqlite.c
@@ -20,6 +20,8 @@
  */
 
 #include <stdlib.h>
+#include <time.h>
+
 #include <sqlite3.h>
 
 #include "debug.h"
@@ -74,11 +76,6 @@ typedef enum
 	GET_ACCOUNT_ID_QUERY_PARAM_PROTOCOLID = 2,
 } GetAccountIdQueryParam;
 
-typedef enum
-{
-	GET_ACCOUNT_ID_QUERY_COL_ID = 0
-} GetAccountIdQueryCol;
-
 static sqlite3_stmt *insert_account_q = NULL;
 
 static const char *insert_account_q_str =
@@ -91,10 +88,22 @@ typedef enum
 	INSERT_ACCOUNT_QUERY_PARAM_PROTOCOLID = 2,
 } InsertAccountQueryParam;
 
+static sqlite3_stmt *get_buddy_id_q = NULL;
+
+static const char *get_buddy_id_q_str =
+	"SELECT Id FROM Buddies "
+	"WHERE Name = ?1 AND AccountId = ?2;";
+
+typedef enum
+{
+	GET_BUDDY_ID_QUERY_PARAM_NAME      = 1,
+	GET_BUDDY_ID_QUERY_PARAM_ACCOUNTID = 2
+} GetBuddyIdQueryParam;
+
 static sqlite3_stmt *insert_buddy_q = NULL;
 
 static const char *insert_buddy_q_str =
-	"INSERT OR IGNORE INTO Buddies (Name, AccountId) VALUES(?1, ?2);";
+	"INSERT INTO Buddies (Name, AccountId) VALUES(?1, ?2);";
 
 typedef enum
 {
@@ -102,12 +111,39 @@ typedef enum
 	INSERT_BUDDY_QUERY_PARAM_ACCOUNTID = 2
 } InsertBuddyQueryParam;
 
+static sqlite3_stmt *get_day_id_q = NULL;
+
+static const char *get_day_id_q_str =
+	"SELECT Id FROM Days WHERE Time = ?1 AND BuddyId = ?2;";
+
+typedef enum
+{
+	GET_DAY_ID_QUERY_PARAM_TIME    = 1,
+	GET_DAY_ID_QUERY_PARAM_BUDDYID = 2,
+} GetDayIdQueryParam;
+
+typedef enum
+{
+	GET_ID_QUERY_COL_ID = 0
+} GetIdQueryCol;
+
+static sqlite3_stmt *insert_day_q = NULL;
+
+static const char *insert_day_q_str =
+	"INSERT INTO Days(Time, BuddyId) VALUES (?1, ?2);";
+
+typedef enum
+{
+	INSERT_DAY_QUERY_PARAM_TIME    = 1,
+	INSERT_DAY_QUERY_PARAM_BUDDYID = 2,
+} InsertDayQueryParam;
+
 static sqlite3_stmt *insert_message_q = NULL;
 
 static const char *insert_message_q_str =
 	"INSERT INTO Messages (Author, AuthorAlias, Recipient, "
-	"Contents, MsgTime, Flags, Seen, Send, AccountId) "
-	"VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9);";
+	"Contents, MsgTime, Flags, Seen, AccountId, BuddyId, DayId) "
+	"VALUES(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10);";
 
 typedef enum
 {
@@ -118,8 +154,9 @@ typedef enum
 	INSERT_MESSAGE_QUERY_PARAM_MSGTIME     = 5,
 	INSERT_MESSAGE_QUERY_PARAM_FLAGS       = 6,
 	INSERT_MESSAGE_QUERY_PARAM_SEEN        = 7,
-	INSERT_MESSAGE_QUERY_PARAM_SEND        = 8,
-	INSERT_MESSAGE_QUERY_PARAM_ACCOUNTID   = 9,
+	INSERT_MESSAGE_QUERY_PARAM_ACCOUNTID   = 8,
+	INSERT_MESSAGE_QUERY_PARAM_BUDDYID     = 9,
+	INSERT_MESSAGE_QUERY_PARAM_DAYID       = 10,
 } InsertMessageQueryParam;
 
 static sqlite3_stmt *get_unseen_msgs_q = NULL;
@@ -140,13 +177,13 @@ static sqlite3_stmt *get_all_msgs_q = NU
 static const char *get_all_msgs_q_str =
 	"SELECT Id, Author, AuthorAlias, Recipient, Contents, MsgTime, Flags "
 	"FROM Messages "
-	"WHERE AccountId = ?1 AND (Author = ?2 OR Recipient = ?2) "
+	"WHERE BuddyId = ?1 AND DayId = ?2 "
 	"ORDER BY MsgTime DESC, Id DESC;";
 
 typedef enum
 {
-	GET_ALL_MSGS_QUERY_PARAM_ACCOUNTID = 1,
-	GET_ALL_MSGS_QUERY_PARAM_WHO       = 2,
+	GET_ALL_MSGS_QUERY_PARAM_BUDDYID = 1,
+	GET_ALL_MSGS_QUERY_PARAM_DAYID   = 2,
 } GetAllMsgsQueryParam;
 
 static sqlite3_stmt *get_older_msgs_q = NULL;
@@ -154,15 +191,13 @@ static sqlite3_stmt *get_older_msgs_q = 
 static const char *get_older_msgs_q_str =
 	"SELECT Id, Author, AuthorAlias, Recipient, Contents, MsgTime, Flags "
 	"FROM Messages "
-	"WHERE AccountId = ?1 AND MsgTime >= ?2 "
-	"AND (Author = ?3 OR Recipient = ?3) "
+	"WHERE BuddyId = ?1 AND MsgTime >= ?2 "
 	"ORDER BY MsgTime, Id;";
 
 typedef enum
 {
-	GET_OLDER_MSGS_QUERY_PARAM_ACCOUNTID  = 1,
+	GET_OLDER_MSGS_QUERY_PARAM_BUDDYID    = 1,
 	GET_OLDER_MSGS_QUERY_PARAM_LOWERBOUND = 2,
-	GET_OLDER_MSGS_QUERY_PARAM_WHO        = 3
 } GetOlderMsgsQueryParam;
 
 static sqlite3_stmt *get_older_msgs_upper_q = NULL;
@@ -170,17 +205,15 @@ static sqlite3_stmt *get_older_msgs_uppe
 static const char *get_older_msgs_upper_q_str =
 	"SELECT Id, Author, AuthorAlias, Recipient, Contents, MsgTime, Flags "
 	"FROM Messages "
-	"WHERE AccountId = ?1 AND MsgTime >= ?2 AND MsgTime <= ?3 AND Id != ?4 "
-	"AND (Author = ?5 OR Recipient = ?5) "
+	"WHERE BuddyId = ?1 AND MsgTime >= ?2 AND MsgTime <= ?3 AND Id != ?4 "
 	"ORDER BY MsgTime, Id;";
 
 typedef enum
 {
-	GET_OLDER_MSGS_UPPER_QUERY_PARAM_ACCOUNTID  = 1,
+	GET_OLDER_MSGS_UPPER_QUERY_PARAM_BUDDYID    = 1,
 	GET_OLDER_MSGS_UPPER_QUERY_PARAM_LOWERBOUND = 2,
 	GET_OLDER_MSGS_UPPER_QUERY_PARAM_UPPERBOUND = 3,
 	GET_OLDER_MSGS_UPPER_QUERY_PARAM_EXCEPTID   = 4,
-	GET_OLDER_MSGS_UPPER_QUERY_PARAM_WHO        = 5
 } GetOlderMsgsUpperQueryParam;
 

_______________________________________________
Commits mailing list
[email protected]
https://pidgin.im/cgi-bin/mailman/listinfo/commits
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.