Update of /cvsroot/freevo/kaa/epg/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29229

Modified Files:
        channel.py guide.py 
Log Message:
speed up search for sqlite2

Index: channel.py
===================================================================
RCS file: /cvsroot/freevo/kaa/epg/src/channel.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** channel.py  7 Jul 2005 09:39:06 -0000       1.3
--- channel.py  17 Jul 2005 12:42:16 -0000      1.4
***************
*** 116,120 ****
          for p in self.__epg.sql_get_programs(self.id, start, stop):
              i = Program(p.id, p.title, p.start, p.stop, p.episode, p.subtitle,
!                         p['description'], channel=self)
              new_progs.append(i)
              notifier_counter = (notifier_counter + 1) % 500
--- 116,120 ----
          for p in self.__epg.sql_get_programs(self.id, start, stop):
              i = Program(p.id, p.title, p.start, p.stop, p.episode, p.subtitle,
!                         p.description, channel=self)
              new_progs.append(i)
              notifier_counter = (notifier_counter + 1) % 500

Index: guide.py
===================================================================
RCS file: /cvsroot/freevo/kaa/epg/src/guide.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** guide.py    17 Jul 2005 09:44:20 -0000      1.3
--- guide.py    17 Jul 2005 12:42:16 -0000      1.4
***************
*** 54,58 ****
          self.channel_dict = {}
  
- 
      def connect(self, frontent, *args):
          """
--- 54,57 ----
***************
*** 75,84 ****
          # will be added if not already in the list
          for c in self.sql_get_channels():
!             if c['id'].encode('latin-1', 'ignore') in tv_channels_exclude:
                  # Skip channels that we explicitly do not want.
                  continue
!             if not c['id'] in self.channel_dict.keys():
!                 self.add_channel(Channel(c['id'], c['display_name'],
!                                          c['access_id'], self))
  
  
--- 74,83 ----
          # will be added if not already in the list
          for c in self.sql_get_channels():
!             id, display_name, access_id = c
!             if id.encode('latin-1', 'ignore') in tv_channels_exclude:
                  # Skip channels that we explicitly do not want.
                  continue
!             if not id in self.channel_dict.keys():
!                 self.add_channel(Channel(id, display_name, access_id, self))
  
  
***************
*** 97,102 ****
          if not type(sql) in StringTypes:
              return sql
!         sql = sql.replace('\'','')
!         return sql
  
  
--- 96,100 ----
          if not type(sql) in StringTypes:
              return sql
!         return sql.replace('\'','')
  
  
***************
*** 184,188 ****
      def search(self, searchstr, by_chan=None, search_title=True,
                 search_subtitle=False, search_description=False,
!                exact_match=False):
          """
          Return a list of programs with a title similar to the given parameter.
--- 182,186 ----
      def search(self, searchstr, by_chan=None, search_title=True,
                 search_subtitle=False, search_description=False,
!                exact_match=False, interval=None):
          """
          Return a list of programs with a title similar to the given parameter.
***************
*** 195,200 ****
              return []
  
!         now = time.time()
!         clause = 'where stop > %d' % now
          if by_chan:
              clause = '%s and channel_id="%s"' % (clause, by_chan)
--- 193,200 ----
              return []
  
!         if interval:
!             clause = 'where stop > %d and start <= %d' % interval
!         else:
!             clause = 'where stop > %d' % time.time()
          if by_chan:
              clause = '%s and channel_id="%s"' % (clause, by_chan)
***************
*** 225,235 ****
  
          query = 'select * from programs %s order by channel_id, start' % 
clause
          result = []
!         for p in self.sql_execute(query):
!             if self.channel_dict.has_key(p.channel_id):
!                 result.append(Program(p.id, p.title, p.start, p.stop,
!                                       p.episode, p.subtitle,
!                                       description=p['description'],
!                                       
channel=self.channel_dict[p.channel_id]))
          return result
  
--- 225,236 ----
  
          query = 'select * from programs %s order by channel_id, start' % 
clause
+ 
          result = []
!         for p in self.sql_execute(query, True):
!             # id, channel_id, start, stop, title, episode, subtitle, \
!             #     description, rating, original_airdate
!             if self.channel_dict.has_key(p[1]):
!                 result.append(Program(p[0], p[4], p[2], p[3], p[5], p[6],
!                                       p[7], self.channel_dict[p[1]]))
          return result
  
***************
*** 243,252 ****
          result = self.sql_execute(query)
          if result:
!             p = result[0]
!             if self.channel_dict.has_key(p.channel_id):
!                 return Program(p.id, p.title, p.start, p.stop,
!                                p.episode, p.subtitle,
!                                description=p['description'],
!                                channel=self.channel_dict[p.channel_id])
          return None
  
--- 244,253 ----
          result = self.sql_execute(query)
          if result:
!             id, channel_id, start, stop, title, episode, subtitle, \
!                 description, rating, original_airdate = result[0]
!             if self.channel_dict.has_key(channel_id):
!                 return Program(id, title, start, stop, episode, subtitle,
!                                description=description,
!                                channel=self.channel_dict[channel_id])
          return None
  
***************
*** 258,272 ****
      #
  
!     def sql_execute(self, query):
          """
!         Execute sql query.
          """
-         query = self.__escape_query(query)
          try:
!             result = self.db.execute(query)
          except TypeError:
              log.exception('execute error')
              return False
-         return result
  
  
--- 259,273 ----
      #
  
!     def sql_execute(self, query, as_list=False):
          """
!         Execute sql query. If as_list is True, the result can only be accessed
!         as a list. So result[0] is possible, result['title'] is not. Using
!         as_list will speed up the query for sqlite2.
          """
          try:
!             return self.db.execute(self.__escape_query(query), as_list)
          except TypeError:
              log.exception('execute error')
              return False
  
  
***************
*** 297,310 ****
  
  
-     def sql_get_channel(self, id):
-         """
-         Get a channel.
-         """
-         query = 'select * from channels where id="%s' % id
-         channel = self.sql_execute(query)
-         if len(channel):
-             return channel[0]
- 
- 
      def sql_get_channels(self):
          """
--- 298,301 ----
***************
*** 332,336 ****
          rows = self.sql_execute(query)
          for row in rows:
!             id_list.append(row.id)
  
          return id_list
--- 323,327 ----
          rows = self.sql_execute(query)
          for row in rows:
!             id_list.append(row[0])
  
          return id_list
***************
*** 354,364 ****
                  'and start>%s and start<%s' % (start, stop)
          rows = self.sql_execute(query)
!         if len(rows) and (len(rows) > 1 or rows[0]['start'] != start or \
!                           rows[0]['stop'] != stop):
              log.info('changed program time table:')
              # The time table changed. Old programs overlapp new once
              # Better remove everything here
              for row in rows:
!                 title = row['title'].encode('latin-1', 'replace')
                  log.info('delete %s:' % title)
                  self.sql_remove_program(row.id)
--- 345,355 ----
                  'and start>%s and start<%s' % (start, stop)
          rows = self.sql_execute(query)
!         if len(rows) and (len(rows) > 1 or rows[0].start != start or \
!                           rows[0].stop != stop):
              log.info('changed program time table:')
              # The time table changed. Old programs overlapp new once
              # Better remove everything here
              for row in rows:
!                 title = row.title.encode('latin-1', 'replace')
                  log.info('delete %s:' % title)
                  self.sql_remove_program(row.id)
***************
*** 371,386 ****
              # An old program is found, check attributes.
              old = rows[0]
!             if old['title'] == title:
                  # program timeslot is unchanged, see if there's anything
                  # that we should update
!                 if old['subtitle'] != subtitle:
                      query = 'update programs set subtitle="%s" where id=%d'
                      self.sql_execute(query % (subtitle, old.id))
                      self.sql_commit()
!                 if old['description'] != description:
                      query = 'update programs set description="%s" where id=%d'
                      self.sql_execute(query % (description, old.id))
                      self.sql_commit()
!                 if old['episode'] != episode:
                      query = 'update programs set episode="%s" where id=%d'
                      self.sql_execute(query % (episode, old.id))
--- 362,377 ----
              # An old program is found, check attributes.
              old = rows[0]
!             if old.title == title:
                  # program timeslot is unchanged, see if there's anything
                  # that we should update
!                 if old.subtitle != subtitle:
                      query = 'update programs set subtitle="%s" where id=%d'
                      self.sql_execute(query % (subtitle, old.id))
                      self.sql_commit()
!                 if old.description != description:
                      query = 'update programs set description="%s" where id=%d'
                      self.sql_execute(query % (description, old.id))
                      self.sql_commit()
!                 if old.episode != episode:
                      query = 'update programs set episode="%s" where id=%d'
                      self.sql_execute(query % (episode, old.id))
***************
*** 392,396 ****
                  # this is probably a schedule change, remove the old one
                  # TODO: check for shifting times and program overlaps
!                 self.sql_remove_program(old['id'])
  
          #
--- 383,387 ----
                  # this is probably a schedule change, remove the old one
                  # TODO: check for shifting times and program overlaps
!                 self.sql_remove_program(old.id)
  
          #



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to