annotate backend/couchdb/CouchDb.py @ 192:9d422fa90096

optimize marking feed entries as read: do not round trip to the database if the entry was already marked as read
author dirk
date Wed, 21 Sep 2011 13:23:25 +0200
parents a4832a180c69
children adf7f617bda9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
169
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
1
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
2 from argparse import ArgumentParser
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
3
180
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
4 database_url = None
178
e8cc86981938 default DB name is feedworm, fix setting the dbname via commandline parameter
dirk
parents: 175
diff changeset
5 database = "feedworm"
169
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
6
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
7 def init():
180
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
8 args = _parseArguments()
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
9 _setDatabaseName(args)
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
10 _setDatabaseUrl(args)
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
11
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
12 def _parseArguments():
169
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
13 parser = ArgumentParser()
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
14 parser.add_argument("--dbname", nargs="?", help="Name of the database")
180
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
15 parser.add_argument("--dburl", nargs="?", help="URL of the database")
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
16 return parser.parse_known_args()
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
17
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
18 def _setDatabaseName(args):
169
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
19 dbname = args[0].dbname
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
20 if dbname is not None:
178
e8cc86981938 default DB name is feedworm, fix setting the dbname via commandline parameter
dirk
parents: 175
diff changeset
21 global database
169
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
22 database = dbname
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
23
180
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
24 def _setDatabaseUrl(args):
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
25 dburl = args[0].dburl
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
26 if dburl is not None:
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
27 global database_url
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
28 database_url = dburl
a4832a180c69 allow setting the URL to the database via command line
dirk
parents: 178
diff changeset
29
169
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
30 #
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
31 # accessor methods for the various views
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
32 #
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
33
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
34 def feedEntriesByFeed():
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
35 return database + "/feedEntries_by_feed"
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
36
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
37 def unreadFeedEntriesByFeed():
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
38 return database + "/unread_feedEntries_by_feed"
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
39
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
40 def feeds():
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
41 return database + "/feeds"
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
42
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
43 def feedEntryByLink():
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
44 return database + "/feedEntry_by_link"
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
45
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
46 def preference():
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
47 return database + "/preference"
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
48
174
d0ced79b5030 implement expiring read feed entries
dirk
parents: 169
diff changeset
49 def readFeedEntriesByCreateDate():
d0ced79b5030 implement expiring read feed entries
dirk
parents: 169
diff changeset
50 return database + "/read_feedEntries_by_create_date"
169
91a24f499318 introdue an abstraction for the name of the database so it can be changed via commandline parameter
dirk
parents:
diff changeset
51
175
57e324fa4350 implement getting a list of feeds that have unread entries
dirk
parents: 174
diff changeset
52 def feedsWithUnreadEntries():
57e324fa4350 implement getting a list of feeds that have unread entries
dirk
parents: 174
diff changeset
53 return database + "/feeds_with_unread_entries"