Skip to content

Commit

Permalink
Version 152
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrusnetwork committed Apr 1, 2015
1 parent 13b132e commit eaa6810
Show file tree
Hide file tree
Showing 31 changed files with 1,048 additions and 318 deletions.
21 changes: 21 additions & 0 deletions help/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@
<div class="content">
<h3>changelog</h3>
<ul>
<li><h3>version 152</h3></li>
<ul>
<li>added prototype hover frame for tags in media view</li>
<li>hover frame shouldn't show when a dialog is open</li>
<li>manage tags dialog launched from media viewer now has a delete button</li>
<li>subscriptions now have an 'initial limit' variable, defaulting to 500, that limits the total number of files the subscription daemon will look for on the initial sync</li>
<li>added a similar file limit spinctrl to gallery download pages</li>
<li>updated layout of import files dialog</li>
<li>cleaned up some ugly global variable scope stuff</li>
<li>fixed initialisation of advanced import options in file import dialog</li>
<li>made a good start to better object serialisation</li>
<li>subscription and repository sync daemon jobs that stop due to a dialog-driven change during processing will now cancel themselves after five seconds</li>
<li>fixed namespace (e.g. 'series:') tag censorship</li>
<li>fixed the fullscreen switch bug that was breaking an (initially fullscreen)->(non fullscreen) media viewer</li>
<li>fixed some search logic (some system predicates were not firing when there were no regular tags present)</li>
<li>removed some artificial delays on daemon db access, let's see if it chokes anything</li>
<li>harmonised a bunch of client and server controller code</li>
<li>created a common controller class and merged a lot of the client and server controller code into it</li>
<li>general code cleanup</li>
<li>more general code cleanup</li>
</ul>
<li><h3>version 151</h3></li>
<ul>
<li>added a possible solution to the manage tags dialog next/previous buttons crash</li>
Expand Down
2 changes: 1 addition & 1 deletion include/ClientCaches.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _GetInfo( self, share_key ):

info[ 'hashes_set' ] = set( hashes )

media_results = wx.GetApp().ReadDaemon( 'media_results', ClientConstants.LOCAL_FILE_SERVICE_KEY, hashes )
media_results = wx.GetApp().Read( 'media_results', ClientConstants.LOCAL_FILE_SERVICE_KEY, hashes )

info[ 'media_results' ] = media_results

Expand Down
4 changes: 4 additions & 0 deletions include/ClientConstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,14 @@
FLAGS_SMALL_INDENT = wx.SizerFlags( 0 ).Border( wx.ALL, 2 )
FLAGS_BIG_INDENT = wx.SizerFlags( 0 ).Border( wx.ALL, 10 )

FLAGS_CENTER = wx.SizerFlags( 2 ).Border( wx.ALL, 2 ).Center()

FLAGS_EXPAND_PERPENDICULAR = wx.SizerFlags( 0 ).Border( wx.ALL, 2 ).Expand()
FLAGS_EXPAND_BOTH_WAYS = wx.SizerFlags( 2 ).Border( wx.ALL, 2 ).Expand()
FLAGS_EXPAND_DEPTH_ONLY = wx.SizerFlags( 2 ).Border( wx.ALL, 2 ).Align( wx.ALIGN_CENTER_VERTICAL )

FLAGS_SIZER_CENTER = wx.SizerFlags( 2 ).Center()

FLAGS_EXPAND_SIZER_PERPENDICULAR = wx.SizerFlags( 0 ).Expand()
FLAGS_EXPAND_SIZER_BOTH_WAYS = wx.SizerFlags( 2 ).Expand()
FLAGS_EXPAND_SIZER_DEPTH_ONLY = wx.SizerFlags( 2 ).Align( wx.ALIGN_CENTER_VERTICAL )
Expand Down
145 changes: 17 additions & 128 deletions include/ClientController.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import HydrusConstants as HC
import HydrusData
import ClientData
import HydrusGlobals

import ClientCaches
import collections
import gc
import ClientData
import hashlib
import httplib
import HydrusConstants as HC
import HydrusController
import HydrusData
import HydrusExceptions
import HydrusGlobals
import HydrusNetworking
import HydrusPubSub
import HydrusSessions
import HydrusServer
import HydrusTags
Expand All @@ -21,11 +18,8 @@
import ClientGUIDialogs
import os
import random
import shutil
import stat
import subprocess
import sys
import threading
import time
import traceback
import wx
Expand All @@ -38,22 +32,9 @@

MAINTENANCE_PERIOD = 5 * 60

class Controller( wx.App ):

def _CheckIfJustWokeFromSleep( self ):

last_maintenance_time = self._timestamps[ 'last_maintenance_time' ]

if last_maintenance_time == 0: return False

# this tests if we probably just woke up from a sleep
if HydrusData.GetNow() - last_maintenance_time > MAINTENANCE_PERIOD + ( 5 * 60 ): self._just_woke_from_sleep = True
else: self._just_woke_from_sleep = False

class Controller( HydrusController.HydrusController ):

def _Read( self, action, *args, **kwargs ): return self._db.Read( action, HC.HIGH_PRIORITY, *args, **kwargs )

def _Write( self, action, priority, synchronous, *args, **kwargs ): return self._db.Write( action, priority, synchronous, *args, **kwargs )
db_class = ClientDB.DB

def BackupDatabase( self ):

Expand All @@ -80,13 +61,6 @@ def BackupDatabase( self ):



def ClearCaches( self ):

self._thumbnail_cache.Clear()
self._fullscreen_image_cache.Clear()
self._preview_image_cache.Clear()


def Clipboard( self, data_type, data ):

# need this cause can't do it in a non-gui thread
Expand Down Expand Up @@ -132,7 +106,7 @@ def Clipboard( self, data_type, data ):

media = data

image_container = wx.GetApp().GetFullscreenImageCache().GetImage( media )
image_container = wx.GetApp().Cache( 'fullscreen' ).GetImage( media )

def THREADWait():

Expand Down Expand Up @@ -178,26 +152,12 @@ def CurrentlyIdle( self ):
return HydrusData.GetNow() - self._timestamps[ 'last_user_action' ] > HC.options[ 'idle_period' ]


def EventPubSub( self, event ):

self._currently_doing_pubsub = True

try: HydrusGlobals.pubsub.WXProcessQueueItem()
finally: self._currently_doing_pubsub = False


def GetDB( self ): return self._db

def GetFullscreenImageCache( self ): return self._fullscreen_image_cache
def DoHTTP( self, *args, **kwargs ): return self._http.Request( *args, **kwargs )

def GetGUI( self ): return self._gui

def GetManager( self, manager_type ): return self._managers[ manager_type ]

def GetPreviewImageCache( self ): return self._preview_image_cache

def GetThumbnailCache( self ): return self._thumbnail_cache

def InitCheckPassword( self ):

while True:
Expand All @@ -221,7 +181,7 @@ def InitDB( self ):

try:

self._db = ClientDB.DB()
HydrusController.HydrusController.InitDB( self )

db_initialised = True

Expand All @@ -242,8 +202,6 @@ def InitDB( self ):



threading.Thread( target = self._db.MainLoop, name = 'Database Main Loop' ).start()


def InitGUI( self ):

Expand All @@ -259,10 +217,9 @@ def InitGUI( self ):
self._managers[ 'undo' ] = ClientData.UndoManager()
self._managers[ 'web_sessions' ] = HydrusSessions.WebSessionManagerClient()

self._fullscreen_image_cache = ClientCaches.RenderedImageCache( 'fullscreen' )
self._preview_image_cache = ClientCaches.RenderedImageCache( 'preview' )

self._thumbnail_cache = ClientCaches.ThumbnailCache()
self._caches[ 'fullscreen' ] = ClientCaches.RenderedImageCache( 'fullscreen' )
self._caches[ 'preview' ] = ClientCaches.RenderedImageCache( 'preview' )
self._caches[ 'thumbnail' ] = ClientCaches.ThumbnailCache()

CC.GlobalBMPs.STATICInitialise()

Expand All @@ -272,11 +229,6 @@ def InitGUI( self ):
HydrusGlobals.pubsub.sub( self, 'RestartServer', 'restart_server' )
HydrusGlobals.pubsub.sub( self, 'RestartBooru', 'restart_booru' )

self.Bind( wx.EVT_TIMER, self.TIMEREventMaintenance, id = ID_MAINTENANCE_EVENT_TIMER )

self._maintenance_event_timer = wx.Timer( self, ID_MAINTENANCE_EVENT_TIMER )
self._maintenance_event_timer.Start( MAINTENANCE_PERIOD * 1000, wx.TIMER_CONTINUOUS )

# this is because of some bug in wx C++ that doesn't add these by default
wx.richtext.RichTextBuffer.AddHandler( wx.richtext.RichTextHTMLHandler() )
wx.richtext.RichTextBuffer.AddHandler( wx.richtext.RichTextXMLHandler() )
Expand All @@ -289,17 +241,8 @@ def InitGUI( self ):
self._db.StartDaemons()


def JustWokeFromSleep( self ):

if not self._just_woke_from_sleep: self._CheckIfJustWokeFromSleep()

return self._just_woke_from_sleep


def MaintainDB( self ):

gc.collect()

now = HydrusData.GetNow()

shutdown_timestamps = self.Read( 'shutdown_timestamps' )
Expand Down Expand Up @@ -334,20 +277,12 @@ def MaintainDB( self ):

def OnInit( self ):

self.SetAssertMode( wx.PYAPP_ASSERT_SUPPRESS )

self._currently_doing_pubsub = False

self._timestamps = collections.defaultdict( lambda: 0 )

self._timestamps[ 'boot' ] = HydrusData.GetNow()

self._just_woke_from_sleep = False
HydrusController.HydrusController.OnInit( self )

self._local_service = None
self._booru_service = None

self.Bind( HydrusPubSub.EVT_PUBSUB, self.EventPubSub )
self._http = HydrusNetworking.HTTPConnectionManager()

try:

Expand All @@ -374,17 +309,6 @@ def PrepStringForDisplay( self, text ):
else: return text.lower()


def Read( self, action, *args, **kwargs ): return self._Read( action, *args, **kwargs )

def ReadDaemon( self, action, *args, **kwargs ):

result = self._Read( action, *args, **kwargs )

time.sleep( 0.1 )

return result


def ResetIdleTimer( self ): self._timestamps[ 'last_user_action' ] = HydrusData.GetNow()

def RestartBooru( self ):
Expand Down Expand Up @@ -564,12 +488,8 @@ def THREADDoFileQuery( self, query_key, search_context ):

service_key = search_context.GetFileServiceKey()

include_current_tags = search_context.IncludeCurrentTags()

media_results = []

include_pending_tags = search_context.IncludePendingTags()

i = 0

base = 256
Expand All @@ -589,47 +509,16 @@ def THREADDoFileQuery( self, query_key, search_context ):

HydrusGlobals.pubsub.pub( 'set_num_query_results', len( media_results ), len( query_hash_ids ) )

self.WaitUntilGoodTimeToUseGUIThread()
self.WaitUntilWXThreadIdle()


HydrusGlobals.pubsub.pub( 'file_query_done', query_key, media_results )


def TIMEREventMaintenance( self, event ):

sys.stdout.flush()
sys.stderr.flush()

self._CheckIfJustWokeFromSleep()

self._timestamps[ 'last_maintenance_time' ] = HydrusData.GetNow()

if not self._just_woke_from_sleep and self.CurrentlyIdle(): self.MaintainDB()


def WaitUntilGoodTimeToUseGUIThread( self ):

while True:

if HydrusGlobals.shutdown: raise Exception( 'Client shutting down!' )
elif HydrusGlobals.pubsub.NoJobsQueued() and not self._currently_doing_pubsub: return
else: time.sleep( 0.00001 )



def Write( self, action, *args, **kwargs ):

if action == 'content_updates': self._managers[ 'undo' ].AddCommand( 'content_updates', *args, **kwargs )

return self._Write( action, HC.HIGH_PRIORITY, False, *args, **kwargs )


def WriteSynchronous( self, action, *args, **kwargs ):

result = self._Write( action, HC.LOW_PRIORITY, True, *args, **kwargs )

time.sleep( 0.1 )

return result
return HydrusController.HydrusController.Write( self, action, *args, **kwargs )


27 changes: 15 additions & 12 deletions include/ClientDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -1931,15 +1931,15 @@ def _GetFileQueryIds( self, search_context ):
else: query_hash_ids.intersection_update( wildcard_query_hash_ids )


if len( sql_predicates ) > 1: query_hash_ids.intersection_update( [ id for ( id, ) in self._c.execute( 'SELECT hash_id FROM files_info WHERE ' + ' AND '.join( sql_predicates ) + ';' ) ] )

else:

if file_service_key != CC.COMBINED_FILE_SERVICE_KEY: query_hash_ids = { id for ( id, ) in self._c.execute( 'SELECT hash_id FROM files_info WHERE ' + ' AND '.join( sql_predicates ) + ';' ) }
elif tag_service_key != CC.COMBINED_TAG_SERVICE_KEY: query_hash_ids = { id for ( id, ) in self._c.execute( 'SELECT hash_id FROM mappings WHERE service_id = ? AND status IN ( ?, ? );', ( tag_service_id, HC.CURRENT, HC.PENDING ) ) }
else: query_hash_ids = { id for ( id, ) in self._c.execute( 'SELECT hash_id FROM mappings UNION SELECT hash_id FROM files_info;' ) }


if len( sql_predicates ) > 1: query_hash_ids.intersection_update( [ id for ( id, ) in self._c.execute( 'SELECT hash_id FROM files_info WHERE ' + ' AND '.join( sql_predicates ) + ';' ) ] )

#

( min_num_tags, num_tags, max_num_tags ) = system_predicates.GetNumTagsInfo()
Expand Down Expand Up @@ -5863,6 +5863,19 @@ def _UpdateDB( self, version ):
self._c.execute( 'UPDATE options SET options = ?;', ( HC.options, ) )


if version == 151:

results = self._c.execute( 'SELECT * FROM yaml_dumps WHERE dump_type = ?;', ( YAML_DUMP_ID_SUBSCRIPTION, ) ).fetchall()

for ( dump_type, dump_name, dump ) in results:

dump[ 'initial_limit' ] = 500

self._c.execute( 'UPDATE yaml_dumps SET dump = ? WHERE dump_type = ? and dump_name = ?;', ( dump, dump_type, dump_name ) )




self._c.execute( 'UPDATE version SET version = ?;', ( version + 1, ) )

HydrusGlobals.is_db_updated = True
Expand Down Expand Up @@ -6172,16 +6185,6 @@ def StartDaemons( self ):
HydrusThreading.DAEMONQueue( 'FlushRepositoryUpdates', ClientDaemons.DAEMONFlushServiceUpdates, 'service_updates_delayed', period = 5 )


def WaitUntilGoodTimeToUseDBThread( self ):

while True:

if HydrusGlobals.shutdown: raise Exception( 'Client shutting down!' )
elif self._jobs.empty() and not self._currently_doing_job: return
else: time.sleep( 0.00001 )



def Write( self, action, priority, synchronous, *args, **kwargs ):

if action == 'vacuum': job_type = 'write_special'
Expand Down
Loading

0 comments on commit eaa6810

Please sign in to comment.