Skip to content
Browse files

Split table definitions from db configuration.

  • Loading branch information...
1 parent bd18256 commit 9f0ec95138276e03a7b14834c6422ed57150ef80 @spladug spladug committed Mar 2, 2012
Showing with 72 additions and 50 deletions.
  1. +56 −37 r2/example.ini
  2. +16 −13 r2/r2/lib/app_globals.py
View
93 r2/example.ini
@@ -183,48 +183,67 @@ hardcache_categories = *:hc:hc
db_app_name = reddit
# are we allowed to create tables?
db_create_tables = True
+# are we allowed to write at all?
+disallow_db_writes = False
type_db = main
rel_type_db = main
hardcache_db = main
-db_table_link = thing, main, main
-db_table_account = thing, main
-db_table_message = thing, main
-
-db_table_savehide = relation, account, link, main
-db_table_click = relation, account, link, main
-
-db_table_comment = thing, comment
-db_table_subreddit = thing, comment
-
-db_table_srmember = relation, subreddit, account, comment
-
-db_table_friend = relation, account, account, comment
-
-db_table_vote_account_link = relation, account, link, vote
-db_table_vote_account_comment = relation, account, comment, vote
-
-db_table_inbox_account_comment = relation, account, comment, main
-db_table_inbox_account_message = relation, account, message, main
-db_table_moderatorinbox = relation, subreddit, message, main
-
-db_table_report_account_link = relation, account, link, main
-db_table_report_account_comment = relation, account, comment, comment
-db_table_report_account_message = relation, account, message, main
-db_table_report_account_subreddit = relation, account, subreddit, main
-
-db_table_award = thing, award
-db_table_trophy = relation, account, award, award
-
-db_table_jury_account_link = relation, account, link, main
-
-db_table_ad = thing, main
-db_table_adsr = relation, ad, subreddit, main
-
-db_table_flair = relation, subreddit, account, main
-
-disallow_db_writes = False
+# definitions of what each table is (probably shouldn't change in .update files)
+# things require no extra info. relation is followed by the names of the related tables
+db_table_link = thing
+db_table_account = thing
+db_table_message = thing
+db_table_savehide = relation, account, link
+db_table_click = relation, account, link
+db_table_comment = thing
+db_table_subreddit = thing
+db_table_srmember = relation, subreddit, account
+db_table_friend = relation, account, account
+db_table_vote_account_link = relation, account, link
+db_table_vote_account_comment = relation, account, comment
+db_table_inbox_account_comment = relation, account, comment
+db_table_inbox_account_message = relation, account, message
+db_table_moderatorinbox = relation, subreddit, message
+db_table_report_account_link = relation, account, link
+db_table_report_account_comment = relation, account, comment
+db_table_report_account_message = relation, account, message
+db_table_report_account_subreddit = relation, account, subreddit
+db_table_award = thing
+db_table_trophy = relation, account, award
+db_table_jury_account_link = relation, account, link
+db_table_ad = thing
+db_table_adsr = relation, ad, subreddit
+db_table_flair = relation, subreddit, account
+
+# which servers to find each table on (likely to change in .update files)
+# first server listed is assumed to be the master, all others are read-only slaves
+# additionally, a "!avoid_master" flag may be added to specify that reads should use the slaves
+db_servers_link = main, main
+db_servers_account = main
+db_servers_message = main
+db_servers_savehide = main
+db_servers_click = main
+db_servers_comment = comment
+db_servers_subreddit = comment
+db_servers_srmember = comment
+db_servers_friend = comment
+db_servers_vote_account_link = vote
+db_servers_vote_account_comment = vote
+db_servers_inbox_account_comment = main
+db_servers_inbox_account_message = main
+db_servers_moderatorinbox = main
+db_servers_report_account_link = main
+db_servers_report_account_comment = comment
+db_servers_report_account_message = main
+db_servers_report_account_subreddit = main
+db_servers_award = award
+db_servers_trophy = award
+db_servers_jury_account_link = main
+db_servers_ad = main
+db_servers_adsr = main
+db_servers_flair = main
## -- traffic analytics --
View
29 r2/r2/lib/app_globals.py
@@ -487,19 +487,22 @@ def split_flags(p):
prefix = 'db_table_'
for k, v in self.config.raw_data.iteritems():
- if k.startswith(prefix):
- params = list(ConfigValue.to_iter(v))
- name = k[len(prefix):]
- kind = params[0]
- if kind == 'thing':
- engines, flags = split_flags(params[1:])
- dbm.add_thing(name, dbm.get_engines(engines),
- **flags)
- elif kind == 'relation':
- engines, flags = split_flags(params[3:])
- dbm.add_relation(name, params[1], params[2],
- dbm.get_engines(engines),
- **flags)
+ if not k.startswith(prefix):
+ continue
+
+ params = tuple(ConfigValue.to_iter(v))
+ name = k[len(prefix):]
+ kind = params[0]
+ server_list = self.config.raw_data["db_servers_" + name]
+ engines, flags = split_flags(ConfigValue.to_iter(server_list))
+
+ if kind == 'thing':
+ dbm.add_thing(name, dbm.get_engines(engines),
+ **flags)
+ elif kind == 'relation':
+ dbm.add_relation(name, params[1], params[2],
+ dbm.get_engines(engines),
+ **flags)
return dbm
def __del__(self):

0 comments on commit 9f0ec95

Please sign in to comment.
Something went wrong with that request. Please try again.