Update.
This commit is contained in:
		
							parent
							
								
									3c6a0944d6
								
							
						
					
					
						commit
						70db15bf27
					
				
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							@ -9,7 +9,7 @@ python:
 | 
				
			|||||||
	$(PYTHON)
 | 
						$(PYTHON)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dump:
 | 
					dump:
 | 
				
			||||||
	$(PYTHON) -m snek.dump
 | 
						@$(PYTHON) -m snek.dump
 | 
				
			||||||
 | 
					
 | 
				
			||||||
run:
 | 
					run:
 | 
				
			||||||
	$(GUNICORN) -w $(GUNICORN_WORKERS) -k aiohttp.worker.GunicornWebWorker snek.gunicorn:app --bind 0.0.0.0:$(PORT) --reload
 | 
						$(GUNICORN) -w $(GUNICORN_WORKERS) -k aiohttp.worker.GunicornWebWorker snek.gunicorn:app --bind 0.0.0.0:$(PORT) --reload
 | 
				
			||||||
 | 
				
			|||||||
@ -1,17 +1,33 @@
 | 
				
			|||||||
 | 
					import asyncio
 | 
				
			||||||
import json 
 | 
					import json 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from snek.app import app
 | 
					from snek.app import app
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async def fix_message(message):
 | 
				
			||||||
 | 
					    message = dict(
 | 
				
			||||||
 | 
					        uid=message['uid'],
 | 
				
			||||||
 | 
					        user_uid=message['user_uid'],
 | 
				
			||||||
 | 
					        text=message['message'],
 | 
				
			||||||
 | 
					        sent=message['created_at']
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    user = await app.services.user.get(uid=message['user_uid'])
 | 
				
			||||||
 | 
					    message['user'] = user and user['username'] or None
 | 
				
			||||||
 | 
					    return message
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def dump_public_channels():
 | 
					async def dump_public_channels():
 | 
				
			||||||
    result = {'channels':{}}
 | 
					    result = {'channels':{}}
 | 
				
			||||||
 | 
					    for channel in app.db['channel'].find(is_private=False,is_listed=True,tag='public'):
 | 
				
			||||||
    for channel in app.db['channel'].find(is_private=False,is_listed=True):
 | 
					        print(f"Dumping channel: {channel['label']}.")
 | 
				
			||||||
        result['channels'][channel['label']] = dict(channel)
 | 
					        result['channels'][channel['label']] = dict(channel)
 | 
				
			||||||
        result['channels'][channel['label']]['messages'] = list(dict(record) for record in app.db['channel_message'].find(channel_uid=channel['uid']))
 | 
					        result['channels'][channel['label']]['messages'] = [await fix_message(record) for record in app.db['channel_message'].find(channel_uid=channel['uid'],order_by='created_at')]
 | 
				
			||||||
 | 
					        print("Dump succesfull!")
 | 
				
			||||||
    print(json.dumps(result, sort_keys=True, indent=4,default=str),end='',flush=True)
 | 
					    print("Converting to json.")
 | 
				
			||||||
 | 
					    data = json.dumps(result, indent=4,default=str)
 | 
				
			||||||
 | 
					    print("Converting succesful, now writing to dump.json")
 | 
				
			||||||
 | 
					    with open("dump.json","w") as f:
 | 
				
			||||||
 | 
					        f.write(data)
 | 
				
			||||||
 | 
					    print("Dump written to dump.json")
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
    dump_public_channels()
 | 
					    asyncio.run(dump_public_channels())
 | 
				
			||||||
 | 
				
			|||||||
@ -20,13 +20,13 @@ class Cache:
 | 
				
			|||||||
        try:
 | 
					        try:
 | 
				
			||||||
            self.lru.pop(self.lru.index(args))
 | 
					            self.lru.pop(self.lru.index(args))
 | 
				
			||||||
        except:
 | 
					        except:
 | 
				
			||||||
            print("Cache miss!", args, flush=True)
 | 
					            #print("Cache miss!", args, flush=True)
 | 
				
			||||||
            return None
 | 
					            return None
 | 
				
			||||||
        self.lru.insert(0, args)
 | 
					        self.lru.insert(0, args)
 | 
				
			||||||
        while len(self.lru) > self.max_items:
 | 
					        while len(self.lru) > self.max_items:
 | 
				
			||||||
            self.cache.pop(self.lru[-1])
 | 
					            self.cache.pop(self.lru[-1])
 | 
				
			||||||
            self.lru.pop()
 | 
					            self.lru.pop()
 | 
				
			||||||
        print("Cache hit!", args, flush=True)
 | 
					        #print("Cache hit!", args, flush=True)
 | 
				
			||||||
        return self.cache[args]
 | 
					        return self.cache[args]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def json_default(self, value):
 | 
					    def json_default(self, value):
 | 
				
			||||||
@ -61,7 +61,7 @@ class Cache:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if is_new:
 | 
					        if is_new:
 | 
				
			||||||
            self.version += 1
 | 
					            self.version += 1
 | 
				
			||||||
            print(f"Cache store! {len(self.lru)} items. New version:", self.version, flush=True)
 | 
					            #print(f"Cache store! {len(self.lru)} items. New version:", self.version, flush=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def delete(self, args):
 | 
					    async def delete(self, args):
 | 
				
			||||||
        if args in self.cache:
 | 
					        if args in self.cache:
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user